Dependency Injection Initialization

前端 未结 5 1761
天涯浪人
天涯浪人 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

    You can say that. Actually AutoFac, ninject etc. have feature for binding the interfaces with classes. So you will need to do that first. I mean to say that you will need to create one class and you will need to ask AutoFac and ninject to bind it with the interface.

    So, when controller will be looking for any particular interface then AutoFac and ninject will just create object of that class and assign it to interface. And as far as initialization is concerned you can initialize the values while binding the class with interface.

提交回复
热议问题