views:

38

answers:

2

I would like to get opinion on the best way to manage the following please. I have an MVC application project, as well as a DomainModel project. The NHibernate mappings and hibernate.cfg.xml are in the DomainModel project which is referenced in the MVC application. This would normally work fine as all my dataaccess would go through the NHibernate connection.

The problem is that I am using the Sql Membership provider so need access to a connection string from directly within Asp.net MVC.

Question 1

Has anyone had this issue before and what would be the cleanest solution? I want to make sure I only have one place that stores the connectionstring.

Question 2

How would I configure NHibernate with two seperate connections, for Debug and Release with the code

#if DEBUG
 connection = configuration.Properties[/*DEBUGconnectionstring-hibernate.cfg.xml*/]
#else
 connection = configuration.Properties[/*RELEASEconnectionstring-hibernate.cfg.xml*/]
#endif 

Currently the only valid property is connection.connection_string.

How would you get around this?

Thanks.

+4  A: 

Maybe moving your nhibernate config information to your project config files (app.config or web.config) solves your problem. For example, I have two projects in one solution. One of them is WCF service and other one is win service. I have following connection information seperatly each project config files.

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
      <property name="default_schema">DUMMY</property>
      <property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
      <property name="connection.connection_string">Data Source=SRV_OLDEV;User Id=USRdummy;Password=USRdummy;</property>

      <property name="proxyfactory.factory_class">
        NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
      </property>
      <property name="show_sql">true</property>
    </session-factory>
  </hibernate-configuration>
NetSide
A: 

I set my connections to NH in code, using FNH. This may not be an option for you, but if it is, this problem goes away.

Corey Coogan