我与我参与的FOSS项目的设置完全相同。它包含'Core'类库中的所有内容(即使是Controllers和Global.asax.cs)。
有大量有效的解决方案,我选择了一个是创建一个设置类,它实际上是一组静态属性,里面,你必须:
public static string ConnectionString
{
get { return ConfigurationManager.ConnectionStrings["MYAPP"].ConnectionString; }
}
注:请确保您的类库将System.Configuration添加为参考。
内,您的应用程序(从HttpApplication的派生类)您在经过设置,但没有什么可以阻止你tighly耦合NH安装与设置类:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
SetupNHibernate();
}
public virtual void SetupNHibernate()
{
NHibernateRepository.Current.Configure(RoadkillSettings.DatabaseType, Settings.ConnectionString, false, Settings.CachedEnabled);
}
如果这是任何使用给你,the source is here.
+1用于简化测试。分开获取配置和使用它 – SHug