开发者

sharp architecture problem

I started to use the latest s#arp architecture (1.9.5.0). I sometimes add some data to the db via a console application using something like this:

Repository<OriginalSequence> SequenceRepository = new Repository<OriginalSequence>();
...
SequenceRepository.SaveOrUpdate(Sequence);
SequenceRepository.DbContext.CommitChanges();

NHibernateSession.Current.Flush();
NHibernateSession.Current.Clear();

Unfortunately, I get:

ServiceLocator has not been initialized; I was trying to retrieve SharpArch.Data.NHibernate.ISessionFactoryKeyProvider

This has to do with DI I think. which is usually only necessary when I use it in a web app or has something fundamentally changed? Thanks.

Christian

PS:

Please note that I start off with:

string[] mappingAssemblies = new string[] { "Bla.Data" };
              开发者_StackOverflow  string configFile = "NHibernate.config";
                NHibernate.Cfg.Configuration config = NHibernateSession.Init(
                        new SimpleSessionStorage(),
                        mappingAssemblies,
                        new AutoPersistenceModelGenerator().Generate(),
                        configFile);

This used to work fine.


This has been fixed in the 1.9.6 release, but you need to register the default implementation of ISessionFactoryKeyProvider in the Windsor container.

In ComponentRegistrar.cs in the CastleWindsor folder of the "Web" project add this code to the AddGenericRepositoriesTo method:

container.Register(
  Component
    .For(typeof(ISessionFactoryKeyProvider))
    .ImplementedBy(typeof(DefaultSessionFactoryKeyProvider))
    .Named("sessionFactoryKeyProvider"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜