views:

186

answers:

2

I have a UnityContainer that gets it's configuration information at runtime in the global.asax file of an MVC web app.

I also have services in another assembly that need access to this container so that they can perform resolutions manually.

How can I best share the two? I don't want to have a reference between my Data assembly and MVC, but I want the data assembly to have access to the UnityContainer that was configured by the web app.

I'm wondering what others are doing in this situation.

A: 

I am using StructureMap (similar tool) and generally share my configuration across projects in a solution. This means that they are not directly sharing the same object per-se unless they are working in the same context. In a simple application where the website is loading the assembly to perform work from the controller to the business layer and then into the dal...they are indeed using the same object. But as soon as you need to put your tier's into physically separate layers (hardware) then the config can go with it. This becomes a deployment issue at that time.

Andrew Siemer
right but there's no config.I had a solution that worked when I was using config files, but after being bit once too many times by large refactorings, I opted out of XML-Hell and am using C# to wire up the container. So where I was sharing config, I now need a different approach.
+1  A: 

I just registered the container into itself, and then let the dependencies cascade throughout the referenced tiers.

ie

// configure container

blah blah blah

// register itself

Container.RegisterInstance(Container);

Then anyone that needs it just has it as a dependent property or constructor param.