.Net Core, LightInject: How to set up DI via properties

141 Views Asked by At

Can't set up dependency injection via properties in a class...

I googled everything and looked through all the documentation, so I couldn't find anything how to configure on .net core mvc... Help me please

HomeController.cs

public class HomeController : Controller
{
    [Inject]
    protected IUserRepository UserRepository { get; set; }

    public HomeController()
    { }
}

DI

public class CompositionRoot : ICompositionRoot
{
   public void Compose(IServiceRegistry services)
   {
       services.RegisterScoped<IUserRepository>, UserRepository>();
   }
}

Constructor injection works well, but property injection fails.

Most likely you need to add some additional package and additional settings, but I do not know what

I use:

  • ASP.NET CORE MVC 3.1
  • LightInject 6.3.4 (latest version)
0

There are 0 best solutions below