使用NHibernate.Caches.MemCached配置Fluent Nhibernate [英] Configure Fluent Nhibernate with NHibernate.Caches.MemCached

查看:203
本文介绍了使用NHibernate.Caches.MemCached配置Fluent Nhibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图配置Fluent NHibernate与MemCache,但我得到以下错误。我使用MVC5 + CastleWindsor + FluentNHibernate + UOW



私有静态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 => FluentMappings.AddFromAssembly(Assembly.GetAssembly(typeof(HotelsMap)))))
.BuildSessionFactory();
}



错误:


[NullReferenceException:对象引用未设置为
对象的实例。]
中的Memcached.ClientLibrary.SockIOPool.Initialize()C:\devroot\memcacheddotnet\trunk\\ \\clientlib\src\clientlib\SockIOPool.cs:441
NHibernate.Caches.MemCache.MemCacheProvider.Start(IDictionary`2
properties)+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()....


提前感谢



这是从SockIOPool.cs文件中获得的:

  ///池必须在使用前进行初始化。这通常应该早在
///在应用程序实例的生命周期。

同一文件具有如下初始化示例:

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

也许你缺少连接池的配置,或者你不是初始化它。 p>

I am trying to configure Fluent NHibernate with MemCache but I get the following error. I am using 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(); }

Error:

[NullReferenceException: Object reference not set to an instance of an object.] Memcached.ClientLibrary.SockIOPool.Initialize() in C:\devroot\memcacheddotnet\trunk\clientlib\src\clientlib\SockIOPool.cs:441 NHibernate.Caches.MemCache.MemCacheProvider.Start(IDictionary`2 properties) +3627
NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) +1098
NHibernate.Cfg.Configuration.BuildSessionFactory() +181
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +73

[FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

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

Thanks in advance

解决方案

It looks to be a problem with the server list not being initialised.

This is from the SockIOPool.cs file:

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

The same file has an initialisation example like this:

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

Maybe you are missing the configuration of the connection pool, or maybe you are not initialising it.

这篇关于使用NHibernate.Caches.MemCached配置Fluent Nhibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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