0
0
0x472DD2019-07-09 00:20:59
ASP.NET
0x472DD, 2019-07-09 00:20:59

How does DI resolve to the controller's .ctor?

Hello. Can you please tell me exactly how the specific implementation of the interface is forwarded to the controller through di?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lil_toady, 2019-07-09
@0x472DD

The question is not very clear.
If about how DI understands which implementation to use - everything is simple, you yourself specify it for a specific interface.
And if you are interested in how DI understands what to pass to a constructor: through reflection, Type has a GetConstructors() method - get a list of ConstructorInfo describing each of the declared constructors. Next, you can get a list of parameters ( ParameterInfo ) via GetParameters() and find one whose parameter types are all known to DI, instantiate them and then instantiate the requested class, such as a controller, using, for example, Activator.CreateInstancewhere the type of the class we need and the list of arguments are passed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question