尖锐的建筑问题 [英] sharp architecture problem

查看:67
本文介绍了尖锐的建筑问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用最新的s#arp体系结构(1.9.5.0).有时我会通过控制台应用程序使用以下方式将一些数据添加到数据库中:

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();

不幸的是,我得到了

ServiceLocator尚未初始化;我正在尝试检索SharpArch.Data.NHibernate.ISessionFactoryKeyProvider

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

我认为这与DI有关.通常只有当我在Web应用程序中使用它或从根本上改变了某些内容时才需要?谢谢.

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.

基督徒

PS:

请注意,我首先开始:

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

这曾经很好用.

推荐答案

此问题已在1.9.6版本中修复,但是您需要在Windsor容器中注册ISessionFactoryKeyProvider的默认实现.

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

在"Web"项目的CastleWindsor文件夹中的ComponentRegistrar.cs中,将此代码添加到AddGenericRepositoriesTo方法中:

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"));

这篇关于尖锐的建筑问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆