내 단위 테스트가 녹색이므로이 반짝이는 새 NHibernate 기반 DAL을 웹 응용 프로그램에 통합 할 시간입니다! 두 개의 구성 파일을 유지하고 싶지 않아 hibernate.cfg.xml을 내 Web.config 파일로 마이그레이션했습니다 (즉, 내 Web.config의 hibernate.cfg.xml 내용을 copypasta'd). , 위해 Application_Start에, 내 구성 초기화하려고의 Global.asax에서ASP.NET 4.0의 Web.config를 통해 NHibernate 구성
<configSections>
<section name="combres" type="Combres.ConfigSectionSetting, Combres, Version=2.0.0.0, Culture=neutral, PublicKeyToken=49212d24adfbe4b4"/>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<nhibernate xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="">
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=(local)\SQLExpress;Initial Catalog=MyProject;Integrated Security=True</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<listener class="MyProject.Sql.Listeners.SaveEventListener, MyProject" type="save"/>
<listener class="MyProject.Sql.Listeners.UpdateEventListener, MyProject" type="update"/>
</session-factory>
</nhibernate>
: 여기 내의 Web.config에서 관련 비트
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
SessionProvider.Initialize();
}
을 모든이 진짜로은에 따라 전화 new Configuration().Configure().AddAssembly("MyProject");
입니다 위의 구성 코드.
재미있는 결과 : 처음 페이지를 명중 할 때 예외가 발생합니다 :
[FileNotFoundException: Could not find file 'D:\Build\MyProject\Source\MyProject.Web\bin\hibernate.cfg.xml'.]
글쎄, 내가의 Web.config의 구성을 넣어, 그것은이 lookign되어서는 안된다? "안녕하세요, NHibernate,주의를 기울여야합니다 - 설정 데이터가 Web.config에 있습니다, 더미!"라고 표시해야합니까? 어딘가에?
그런 다음 F5를 누르면 페이지가 나타납니다. 만세! 지금은 데이터 액세스와 뭔가를 시도하고 나는이 예외를 얻을 : -이 hibernate.cfg.xml 내에서 구성으로 시험에 잘했습니다 ... 그리고 나는
[ProxyFactoryFactoryNotConfiguredException: The ProxyFactoryFactory was not configured.
Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.
Example:
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
Example:
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>]
허, 즉 너무 좀 이상해 내 Web.config에서이 속성을 지정하면 ... 무슨 일이 일어날 지 궁금합니다.
누구든지 아이디어가 있습니까? 이 수수께끼를 푸는 데 도움이 될 것입니다!
* 업데이트 : 문제점을 발견했습니다. 그것은 내 configs 섹션에서 올바른 유형을 사용하지 않는 것 같습니다! 오. I have a complete write up on my blog.
매우 유용합니다. 많은 분들께 감사드립니다. – Simian