Unity using DI config with ASP.NET N-tier solution.

Dec 1, 2013 at 1:31 PM
My problem is that the Web.config contains the DI mapping. So all the N-tier must be reference in the ASP.NET project in order for the mapping to be valid. I don't want that. I don't want to set references to other tiers at the UI project layer so things are mapped in the Web.config.

How can I use a DI.config that will be common to all the tiers, even the UI tier since it is using Unity to instantiate the Service layer that is passed into the Presenter of a MVP solution. I don't want to use the Web.config for Unity DI mapping.

Service Layer

Service Layer, BLL and DAL are using Unity

Dec 2, 2013 at 12:40 PM
I didn't understand why you need to reference the asp.net project.

global.asax should initialize the container, and them you should pass the container to the other layers.

can you show an example the way you are doing this?
Dec 2, 2013 at 4:45 PM
Thank you for your response. I did find out that I didn't need the references to the other layers at the ASP.NET project. I was confused, because in the Web.config and the Unity mapping, the entries for namespace, Interface and class locations changed to a different color when the references to the layers were in the ASP.NET project, which indicated that the items were found in the solution. I removed the references out of the ASP.NET project and everything still worked.
Dec 3, 2013 at 6:04 AM
I think this answer and diagram by Mark Seeman illustrates the different dependency graphs nicely.

If you are using XML configuration then you strictly speaking don't need a hard reference in the web project as long as the assemblies are resolvable at runtime.

Randy Levy
Enterprise Library support engineer
Support How-to