Refactoring a large application for ObjectFactory.GetInstance to use nested containers

I have a great application that uses the old way of getting instances using ObjectFactory.GetInstance ().

Now I want to move on to the application in a more correct way to input dependencies using the constructor insert. However, it is practically impossible to convert all the code at once (some static classes use ObjectFactory.GetInstance, other services do not have constructors with all the dependencies, ...).

I was wondering if there is a way to replace ObjectFactory.GetInstance calls with a replacement that uses the current nested container, for example. replacing all ObjectFactory.GetInstance with Ioc.GetCurrentNestedContainer (). GetInstance to quickly launch it. But how can I implement Ioc.GetCurrentNestedContainer to return the current active nested container?

I cannot inject IContainer into all of these classes (some of them are static or do not have a corresponding constructor), so they cannot use constructor injection (for now).

DI is used in MVC, WCF, and Task scripts in this application.

+4
source share
1 answer

WCF , MVC ( .

, StructureMap, , HttpContext HttpContext.Items. , , HttpContext.Items, IContainer.

Infact, , narget StructureMap.MVC5.

ObjectFactory factory, HttpContext.Items.

Update:

HttpContext , , , factory, Lazy<T> , GroupsMap StructureMap .

StructureMap Google, , . StructureMap, , , .

+1

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


All Articles