views:

25

answers:

1

I have my NHibernateUtil class in the infrastructure layer of my application, however I arrive at a problem with this line:

...
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Computer>());

For this to work I have to expose the domain layer to the infrastructure layer. The domain layer also has access to the infrastructure layer due to the mappings (e.g. ComputerMapping) and this causes a circular dependency.

How does one tell configure FluentNHibernate to access the correct assembly without giving the infrastructure layer access to the domain layer?

+1  A: 

I don't understand why you need to reference the infrastructure layer inside your domain layer. Normally you should structure it like this:

  • Domain containing domain classes and interfaces which define operations on these classes

  • Data access layer referencing the domain layer and implementing the interfaces for a given provider (for example SQL qith NHibernate). Here you put the fluent nhibernate mapping classes and the configuration allowing you to construct an ISessionFactory used in the implementation of the interfaces. You only expose the implementation of these interfaces, everything else is private.

  • Main application referencing the previous two layers. Here you might use an object container to select the proper implementation of the domain interfaces.

If later you decide to use some other technology to access your data such as Entity Framework for example you need to write another data access layer with a different implementation of the domain interfaces and plug it in the main application by modifying only the object container (DI) code.

Darin Dimitrov
Thanks for the quick response, so you place your mappings in the infrastructure layer then, is it OK for the infrastructure layer to have access to the domain?
Laz

related questions