James
James

Reputation: 2009

Avoiding assembly references when using IoC in multi layer app

Quick question so I start in the right direction. I have a multi project solution with an MVC presentation layer. Currently this layer only knows about an IServices class library. Now if I want to use an IoC it seems like I will have to start adding references to all of the other projects in my solution in the MVC application so that I can configure the IoC.

Is this right or should each layer have its own IoC?

Thanks,

James

Upvotes: 4

Views: 230

Answers (1)

mnemosyn
mnemosyn

Reputation: 46341

Someone must load the .dll files, and someone be able to wire up the IoC.

Typically, the dll loading happens automatically and the IoC wiring happens in a nearly-hardcoded fashion.

You could load libraries dynamically: you can write code that tries to load each dll in a given folder and invoke some kind of GetLibraryDescriptor method. That method tells you that the library provides an implementation for, say, ISomeInterface. Now you can ask the dll to instantiate an object of that class it provides. You'd probably have to bridge this instantiation to the IoC. I believe that such a design is better suited for a service locator.

All this makes sense for shrink-wrap software, but I don't see many benefits for web software.

The only reason not to reference other libraries I see is to make sure nobody directly uses or access the code that is declared in there - a tedious task, a sometimes impossible goal that moves encapsulation to the wrong level. If your classes are well-encapsulated, it shouldn't be necessary.

Upvotes: 1

Related Questions