开发者

Has anyone managed to write a fluent version of adding the Castle NHibernate Facility?

Has anyone managed to do this?

Basically I am looking for the following:

<?xml version="1.0"?>
<configuration>
  <facilities>
    <facility id="nhibernate"
                isWeb="false"
                type="Castle.Facilities.NHibernateIntegration.NHibernateFacility, Castle.Facilities.NHibernateIntegration"
        configurationBuilder="FS.SUV.Services.FluentNHibernateConfigBuilder, FS.SUV.Services">
      <factory id="nhibernate.factory">
        <settings>
          <item key="show_sql">false</item>
          <item key="connection.provider">NHibernate.Connection.DriverConnectionProvider</item>
          <item key="connection.driver_class">NHibernate.Driver.SqlClientDriver</item>
          <item key="dialect">NHibernate.Dialect.MsSql2008Dialect</item>          
          <item key="connection.connection_string_name">DBConnection</item>
          <item key="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory , NHibernate.ByteCode.Castle</item>
        </settings>
      </factory>
    </facility>       
  </facilities> 
</configuration>

And the corresponding code to install this would be

 container
   .Install(Castle.Windsor.Installer.Configuration.FromXmlFile("Windsor.config"))

Where Windsor.config is the xml above.

In a fluent form

Typyically you can do stuff like

             .AddFacility<NHibernateFacility>("NHibernate", cfg=>cfg.FacilityConfig)

However from the options in Intellisense it is unclear if anything will provide what I want from the xml snippet above.

I have done some searches which have returned the following which either do not work or refer to a previous version. I am using NHibernate 2 for this one project with Castle.

Tuna Toksoz post

But with no joy. Can anyone help! I know, I know I could always use a different IOC! But I am curious if anyone else has come across this issue. I can also just leave it as xml but I p开发者_如何学运维refer the fluent configuration because I can then dynamically set connections strings and other factory properties at will.

Any help will be most appreciated.


Yes, there's a fluent NHibernate Facility at https://github.com/haf/Castle.Facilities.NHibernate.

You configure it using FluentNHibernate and then you can have session-per-transaction, session-per-web request or session-transient lifestyles.


As far as I know, nobody finished implementing the fluent interface. It certainly isn't present in the code repository. Which gives you the opportunity to implement it and contribute it to the project! Get in touch with Tuna if you're up for it.

Otherwise, remember that Windsor configuration can be built programmatically. It might not be as pretty as a fluent interface, but it's not XML either. Here's an example of the NHibernate facility being configured programmatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜