开发者

Fluent Nhibernate external configuration

All examples of fluent nhibernate make such(or similar) call:

c.AddMappingsFromAssembly(typeof(Product).Assembly);

I don't want tu use "typeof(Product).Assembly" as i don't want to have reference to my domain project here ("Procuct" class). In ordinary NHibernate I would just create hbm.xml files and make following entry in web.config:

  <mapping assembly="TestingFluentHN"/>

but this entry does not work with FluentNHibernate. Is there an elegant way of providing assemblies in my session-building method? Preferably from configuration file.

Resources: Context of unwanted code/dependency:

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();
}

My first idea was to read assemblies names from appSettings and load them:

var assembliesToMap = new List<string>();
foreach (var assemblyName in assembliesToMap)
{
    var assembly = Assembly.LoadFile(assemblyName);
    c.AddMappingsFromAsse开发者_如何学JAVAmbly(assembly);
}

but that is my last option. I'm looking for sth build in fluent nhibernate.


I'm not aware of anything built into fluent nhibernate that will do what you want. You'll probably need to use the method you laid out in the end of your question.

I'm not sure if I'm just not getting the right picture of how your application is laid out, but the whole idea seems a bit misguided. You will need to take a dependency on the domain objects to query the session anyway, and it seems likely that this would be in the same assembly as the session factory's creation. If not, you may consider using dependency injection to provide a session manager (from a project that is aware of the domain objects).

If I'm missing something please let me know.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜