Sometimes when using dependency injection it is necessary to use the parameters used in the constructor. This is what is supported in Unity (and other containers for dependency injection), so when it tries to instantiate a type, it can provide your arguments as parameters in the constructor.
My question is: is this approach appropriate?
It is impossible to specify in the interface what parameters the implementation class should have. By specifying Unity parameters, you assume that the implementation class has these parameters, and you set implicit restrictions for future implementation classes. These restrictions cannot be transmitted through the interface.
So, this is a flaw in the way the interfaces themselves are specified (in .NET), for example. Should constructor records be specified? Or was this feature (the ability to provide constructor parameters) included in Unity due to some other need?
The only real applicable approach (for me) seems to use the factory to create implementation classes and inject dependencies into the factory.
I understand that my question here may be unclear, so I will ask it a little differently: what is the best way to inject dependencies in a class that has a constructor that requires parameters?
(I do not think this question is subjective, since there is probably one design pattern for this type of dependency injection.)
EDIT:
, , , ( , ).