How to use Func <T> in the built-in dependency injection
Using asp.net 5 , I would like my controller to introduce Func<T> instead of T
For instance:
public HomeController(Func<Interfaces.IUnitOfWork> uow) Instead
public HomeController(Interfaces.IUnitOfWork uow) Is this possible with the built-in DI or am I forced to switch to an external DI?
+5
2 answers
Func<T> not registered and is not allowed by default, but there is nothing that would prevent you from registering it yourself.
eg.
services.AddSingleton(provider => new Func<IUnitOfWork>(() => provider.GetService<IUnitOfWork>())); Please note that you also need to register IUnitOfWork as usual.
+2