使用NHibernate.Caches.MemCached配置Fluent Nhibernate

时间:2014-05-22 21:26:04

标签: configuration fluent-nhibernate memcached castle-windsor

我正在尝试使用MemCache配置Fluent 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()in   C:\ devroot \ memcacheddotnet \干线\ clientlib的\ src \ clientlib \ SockIOPool.cs:441   NHibernate.Caches.MemCache.MemCacheProvider.Start(IDictionary`2   属性)+3627
  NHibernate.Impl.SessionFactoryImpl..ctor(配置cfg,IMapping   映射,设置设置,EventListeners监听器)+1098
  NHibernate.Cfg.Configuration.BuildSessionFactory()+ 181   FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()+73

     

[FluentConfigurationException:配置无效或不完整   在创建SessionFactory时使用。检查PotentialReasons   集合和InnerException以获取更多细节。

     

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

提前致谢

1 个答案:

答案 0 :(得分:0)

服务器列表未初始化似乎存在问题。

这是来自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();  

也许您错过了连接池的配置,或者您可能没有初始化它。

相关问题