Reputation: 131
What would be the best way to implement fluent-nhibernate regarding project architecture?
I have two projects at the moment one for the domain layer and the other is the persistance layer. My problem is that when trying to configure nhibernate I get a circular reference.
The domain references the persistance layer but how do I get the configuration to work without having to reference the domain in the persistance layer i.e. the product class in this line AddFromAssemblyOf()?
Currently my configuration is like this.
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("DisillStoreConnectionString")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Product>()))
.BuildSessionFactory();
Upvotes: 1
Views: 251
Reputation: 7834
You'll want your Fluent config class in your persistence project with your ClassMap
classes, not your domain models.
Using your code sample, you'd want to AddFromAssemblyOf
on your Map
class and not your Model
class. See:
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(
c =>
c.FromConnectionStringWithKey("DisillStoreConnectionString")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<ProductMap>()))
.BuildSessionFactory();
This way, your domain project doesn't need to reference your persistence project.
Upvotes: 1