Dependency Injection Initialization

Viewed 6134

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?

How is this?

private IMyService iMyService;
public HomeController(IMyServices myService)
{
    iMyService = myService;
}

Different from...

public IMyService iMyService = new MyService();

Lastly, it seems like the dependency still exists.

Edit: Fixed typo, new MyService(); was new IMyService();

5 Answers
Related