The problem is that you are calling new MyService() , the ASP.NET 5 injection system is completely ruled out.
To have the dependencies introduced in MyService , we must let ASP.NET create an instance for us.
If you want to use MyService in your controller, you can first register it using a set of services along with IMyClass .
services.AddTransient<IMyClass, MyClass>(); services.AddTransient<MyService>();
In this case, I decided to use constructor injection, so I'm not mistaken in trying to create an instance of MyService myself:
public class MyService { public IMyClass myClass { get; set; } public MyService(IMyClass myClass) { this.myClass = myClass; } public void DoSomething() {
Now you can enter this service in your controller:
public class HomeController : Controller { [FromServices] public MyService myService { get; set; } public IActionResult Index() {
If you want to know more about ASP.NET 5 dependency injection system, I made a video and blog here: http://dotnetliberty.com/index.php/2015/10/15/asp-net-5-mvc6-dependency-injection -in-6-steps /
source share