流利的 nhibernate 的所有示例都进行了此类(或类似)调用:
c.AddMappingsFromAssembly(typeof(Product).Assembly);
我不想你使用“typeof(Product).Assembly”,因为我不想在这里引用我的域项目(“Procuct”类)。在普通的 NHibernate 中,我只需创建 hbm.xml 文件并在 web.config 中进行以下条目:
<mapping assembly="TestingFluentHN"/>
但此条目不适用于 FluentNHibernate。在我的会话构建方法中是否有一种优雅的方式来提供程序集?最好来自配置文件。
资源:不需要的代码/依赖的上下文:
static NHSessionManager()
{
Configuration c = new Configuration();
//change following to sth that does not need refernce to domain
c.AddMappingsFromAssembly(typeof(Product).Assembly);
c.Configure();
sessionFactory = c.BuildSessionFactory();
}
我的第一个想法是从 appSettings 读取程序集名称并加载它们:
var assembliesToMap = new List<string>();
foreach (var assemblyName in assembliesToMap)
{
var assembly = Assembly.LoadFile(assemblyName);
c.AddMappingsFromAssembly(assembly);
}
但这是我最后的选择。我正在寻找流畅的 nhibernate 构建。