Castle Windsor 3 + Fluent NHibernate + Castle.NHibernate.Integration
Posted
技术标签:
【中文标题】Castle Windsor 3 + Fluent NHibernate + Castle.NHibernate.Integration【英文标题】: 【发布时间】:2012-01-23 08:19:36 【问题描述】:我创建了一个示例项目来复制我在使用 Castle Windsor 和 NHibernate 集成设施时遇到的问题。
我得到以下异常:
Method not found: 'Void Castle.Core.DependencyModel..ctor(Castle.Core.DependencyType, System.String, System.Type, Boolean)'.
使用以下堆栈跟踪:
at Castle.Facilities.NHibernateIntegration.Internal.NHSessionComponentInspector.ProcessModel(IKernel kernel, ComponentModel model)
at Castle.MicroKernel.ModelBuilder.DefaultComponentModelBuilder.<>c__DisplayClass6.<BuildModel>b__4(IContributeComponentModelConstruction c)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at Castle.MicroKernel.ModelBuilder.DefaultComponentModelBuilder.BuildModel(IComponentModelDescriptor[] customContributors)
at Castle.MicroKernel.Registration.ComponentRegistration`1.Castle.MicroKernel.Registration.IRegistration.Register(IKernelInternal kernel)
at Castle.MicroKernel.DefaultKernel.Register(IRegistration[] registrations)
at Castle.Facilities.NHibernateIntegration.NHibernateFacility.RegisterDefaultConfigurationBuilder()
at Castle.Facilities.NHibernateIntegration.NHibernateFacility.RegisterComponents()
at Castle.Facilities.NHibernateIntegration.NHibernateFacility.Init()
at Castle.MicroKernel.Facilities.AbstractFacility.Castle.MicroKernel.IFacility.Init(IKernel kernel, IConfiguration facilityConfig)
at Castle.MicroKernel.DefaultKernel.AddFacility(IFacility facility)
at Castle.Windsor.WindsorContainer.AddFacility(IFacility facility)
at Castle.Windsor.Installer.DefaultComponentInstaller.SetUpFacilities(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter)
at Castle.Windsor.Installer.DefaultComponentInstaller.SetUp(IWindsorContainer container, IConfigurationStore store)
at Castle.Windsor.WindsorContainer.Install(IWindsorInstaller[] installers, DefaultComponentInstaller scope)
at Castle.Windsor.WindsorContainer.Install(IWindsorInstaller[] installers)
at CW3_FluentNH_Integration_Tester.Main.Main() in D:\Documents and Settings\cannizrm\Desktop\Windsor3FluentTester\CW3_FluentNH_Integration_Tester\CW3_FluentNH_Integration_Tester\Main.vb:line 28
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
我有以下 DLL 版本:
Castle.Core.dll - 3.0.0.2230
Castle.Windsor.dll - 3.0.0.2325
Castle.Facilities.NHibernateIntegration.dll - 1.1.039
FluentNHibernate.dll - 1.3.0.717
Iesi.Collections.dll - 3.2.0.4000
NHibernate.dll - 3.2.0.4000
这是我用来加载容器并安装 Fluent NH 配置的示例代码:
Imports Castle.Windsor
Module Main
#Region " Declarations "
Private objContainer As IWindsorContainer
#End Region
#Region " Properties "
Public ReadOnly Property Container As IWindsorContainer
Get
If objContainer Is Nothing Then
objContainer = New WindsorContainer()
End If
Return objContainer
End Get
End Property
#End Region
#Region " Functions "
Sub Main()
Container.Install(Castle.Windsor.Installer.Configuration.FromXmlFile ("Configs\hibernate.cfg.xml"))
End Sub
#End Region
End Module
这是使用的示例 XML 配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<facilities>
<facility id="nhibernate" isWeb="false" type="Castle.Facilities.NHibernateIntegration.NHibernateFacility, Castle.Facilities.NHibernateIntegration">
<factory id="nhibernate.factory">
<settings>
<item key="show_sql">true</item>
<item key="connection.provider">NHibernate.Connection.DriverConnectionProvider</item>
<item key="connection.driver_class">NHibernate.Driver.SqlClientDriver</item>
<item key="dialect">NHibernate.Dialect.MsSql2005Dialect</item>
<item key="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True</item>
</settings>
</factory>
</facility>
</facilities>
</configuration>
【问题讨论】:
我已经在 Castle Windsor 开发邮件列表中发布了一个可能的解决方案。当帐户限制没有到位时,我会将其添加到有效答案中。 是的,这显然是 NHibernateIntegration 没有为 Windsor 3 更新的情况。 是的,没错。我在开发中的帖子的链接。邮件列表在这里:groups.google.com/group/castle-project-devel/browse_thread/…。我只是在等着看是否值得为它创建一个补丁。 是的,总是发送补丁。永远不要等待确认。要“积极主动”(我知道的愚蠢词,但它确实适用于此)。最坏的情况,它会被拒绝,但它可能不会。 【参考方案1】:我已在项目跟踪器上将此问题注册为一个问题,并包含两个补丁文件来解决它。
http://issues.castleproject.org/issue/FACILITIES-156
【讨论】:
以上是关于Castle Windsor 3 + Fluent NHibernate + Castle.NHibernate.Integration的主要内容,如果未能解决你的问题,请参考以下文章
如何访问 Castle Windsor 的 Fluent Interfaces API?
Castle.Windsor依赖注入的高级应用_Castle.Windsor.3.1.0