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" };
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"));
来源:https://stackoverflow.com/questions/5119444/sharp-architecture-problem