Your problems are confusing the term Injection Dependency and struggling with how the ASP.NET MVC environment works.
Also, you are using the term “Dependency Injection” in the wrong context. You are trying to use a hammer as a chisel.
MasterPages and views in ASP.NET MVC are designed to be used as templates. As indicated in another answer, childish activities solve your problem.
For future reference:
Dependency Injection is a tool for setting parameters that you need to enter in class constructors and do it automatically for you, overriding some of the default values for frameworks. The purpose of this is to decouple the components so that they become more reusable, more verifiable, more unitary, among other good things.
DI refers to a problem with the code and solves the problem, not the problem with the user interface.
What you are trying to do is simply impossible. That is, to enter “dependencies” through the designers and properties into the main page. Again, MasterPages are designed by ASP.NET MVC for use as templates. They do not have the code behind the class to create an instance through the constructor, which allows you to enter dependencies in it.
In other words, you are fighting with the frame, which means that you do not understand this.
If this sounds like nitpicking, I think it needs to be highlighted, because otherwise you will confuse yourself and others who read this stream in the future.
source share