design patterns - Calling DI Container directly in method code (MVC Actions) -


I'm playing with DI (using unity). I have learned how to construct constructor and property injection. I have a static container that has been exposed through a property in my Global.assx file (MVCAPication class).

Many different objects are needed in my controller. The constructor is not right to take these things in large amounts, and partly because they are only necessary in some method of action.

The question is, is there anything wrong with just calling your containers directly from the action methods?

  Public Action Result Foo () {IBR Bar = (Bar) MVCAction. Container. Risoll (IBR); // ... times uses a default constructor, I'm not actually doing any injection, I'm just telling my connor that to give me the bar, when I ask for IBR, then I can say that the existence of concrete This is the simplest and most effective way of working, but I've never seen an example like this. 

Is there something wrong with that? Am I missing the concept in some way?

Yes, there is something wrong in using a stable service locator Because

Constructor injection is your best option if the constructor becomes very large, it is an indication that the controller is a violation and you should.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -