Or instead of creating the object itself, do they somehow intercept or capture the creation of the object (for example, a controller created using the MVC structure) and pass all the dependencies that they are required to?
I understand that they must do something when the object is created to use the constructor injection, but I don’t understand whether the containers need to be created to create or if they somehow intercept the creation of the object.
Whatever the answer, are all DI containers doing it this way?
I understand that this question is probably obvious to most familiar with tools such as StructureMap, Unity, Ninject, etc., but I'm new to them and realized that I really don't know how they work under covers. I scour the Internet and cannot find a good answer.
DI/IoC, , . new Something(dependency1, dependency2)... " Something" (, - ). Something, ( Something ).
new Something(dependency1, dependency2)
Something
, Something, - , , , . ( ... , , , Something .)
.
, , - .
, , ( ) , , , ( " " ). , , , .
var foo = new Foo( new Bar() ); container.BuildUp( foo );
, , - a factory . , factory, , , factory :
container.RegisterType<IFoo>( new InjectionFactory( c => new Foo( new Bar() ) ) );