Dependency Injection Initialization

前端 未结 5 1763
天涯浪人
天涯浪人 2021-02-06 14:47

Please note: I have just started using AutoFac to learn about DI and IoC.

Is dependency injection supposed to be initialized in the controllers constructor?

Ho

5条回答
  •  独厮守ぢ
    2021-02-06 15:28

    Edit, the dependency always "exists" but it was moved outside of the class notice that IMyServices can now be defined in the same project as HomeController when MyService is in totally another class. and your DLL with HomeController can compile without knowing about your MyService dll effectivly decoupling them.


    this is a very complex topic and you should read a book about it. reading blogs videos and so on didn;t really help.

    this is a good book. http://www.amazon.com/Dependency-Injection-NET-Mark-Seemann/dp/1935182501

    this is a great vidoe lecture series first 5 videos are about DI in general http://channel9.msdn.com/Blogs/mtaulty/Prism--Silverlight-Part-1-Taking-Sketched-Code-Towards-Unity

    initilization is focused in a COMPOSITION ROOT http://blog.ploeh.dk/2011/07/28/CompositionRoot/

    and the pattern you shown here is CONSTRUCTOR INJECTION

    https://softwareengineering.stackexchange.com/questions/177649/what-is-constructor-injection

提交回复
热议问题