I do not fully understand the meaning of using DI (for example autofac ). Perhaps I do not correctly interpret its meaning because of the wrong scope.
The context of the task is the following: it is necessary to implement the autofac module in the testing system. Actually the problem is, why should I write code with dependency resolution through the same autofac if I can explicitly create objects and transfer them to the constructor.
For example, there is ApiController , he has a bunch of arguments in the constructor, such as user context, registration manager, manager for sending SMS, etc. All these objects, in turn, are also quite difficult to initialize. For example:
Option with Autofac
ISomeClassInterface someClass; var builder = new ContainerBuilder(); builder.RegisterType<SomeService>(); var container = builder.Build(); someClass = new SomeClass(container.Resolve<SomeService>(); Option without Autofac
ISomeClassInterface someClass; ISomeService service = new SomeService(some arguments...); someClass = new SomeClass(service);
SomeServiceas an argument in the constructor of the classSomeClass. And I understand that yourcontainer.Resolveshould returnSomeClass- koks_rs