配置功能NHibernate与NHibernate.Caches.MemCached(Configu

2019-10-20 04:47发布

我想配置功能NHibernate与内存缓存,但我得到了下面的错误。 我使用MVC5 + CastleWindsor + FluentNHibernate + UOW

private static ISessionFactory CreateNhSessionFactory() { var connStr = System.Configuration.ConfigurationManager.ConnectionStrings["AESConnect"].ConnectionString; return Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(connStr)) .Cache(c=>c.ProviderClass(typeof(NHibernate.Caches.MemCache.MemCacheProvider).AssemblyQualifiedName).UseSecondLevelCache()) .ExposeConfiguration(e=>e.SetProperty("hibernate.cache.use_second_level_cache","true")) .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetAssembly(typeof(HotelsMap)))) .BuildSessionFactory(); }

错误:

[的NullReferenceException:对象没有设置为一个对象的一个​​实例。] Memcached.ClientLibrary.SockIOPool.Initialize()在C:\ devroot \ memcacheddotnet \树干\ clientlib \ SRC \ clientlib \ SockIOPool.cs:441 NHibernate.Caches.MemCache .MemCacheProvider.Start(IDictionary`2属性)3627
NHibernate.Impl.SessionFactoryImpl..ctor(配置CFG,IMapping映射,设置设置,事件侦听器监听器)1098
NHibernate.Cfg.Configuration.BuildSessionFactory()+181
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()+73

[FluentConfigurationException:创建一个会话使用了无效的或不完整的结构。 检查PotentialReasons集合,的InnerException了解更多详情。

] FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()117 AESRepositories.Installers.AESInstaller.CreateNhSessionFactory()....

提前致谢

Answer 1:

它看起来是有没有被初始化的服务器列表中的问题。

这是从SockIOPool.cs文件:

/// The pool must be initialized prior to use. This should typically be early on
/// in the lifecycle of the application instance.

同样的文件有这样一个初始化例子:

/// String[] serverlist = {"cache0.server.com:12345", "cache1.server.com:12345"};
///
/// SockIOPool pool = SockIOPool.GetInstance();
/// pool.SetServers(serverlist);
/// pool.Initialize();  

也许你缺少的连接池的配置,或者你没有初始化它。



文章来源: Configure Fluent Nhibernate with NHibernate.Caches.MemCached