Avoiding build references when using IoC in a tiered application

Quick question, so I'm starting in the right direction. I have a multi-project solution with an MVC presentation level. This layer currently knows about the IServices class library. Now, if I want to use IoC, it seems to me that I will need to add links to all other projects in my solution in the MVC application so that I can configure IoC.

Is this correct or does each layer have its own IoC?

Thanks,

James

+4
source share
1 answer

Someone has to load DLL files, and someone will be able to connect IoC.

Typically, dll loading is automatic and the IoC wire is almost hard.

You can dynamically load libraries: you can write code that tries to load each dll in a given folder and call some GetLibraryDescriptor method. This method tells you that the library provides an implementation, for example, ISomeInterface . Now you can ask the dll to instantiate the object of this class that it provides. You will probably have to reduce this instance to IoC. I believe that such a design is better suited for a service locator.

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

The only reason not to refer to the other libraries that I see is to make sure that no one is using or referring to the code declared here - a tedious task, sometimes an impossible goal, that moves encapsulation to the wrong level. If your classes are well encapsulated, this is not necessary.

+1
source

Source: https://habr.com/ru/post/1383911/


All Articles