-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Description
Is your feature request related to a problem? Please describe.
public class MyController : Controller
{
public MyController(Func<MyItem> itemFactory)
{
Item = itemFactory.Invoke();This should work out of box. However it only works if you manually register this dependecy ala
services.AddSingleton<Func<MyItem>>(provider => provider.GetService<MyItem>);Describe the solution you'd like
To understand Func<> as a constructor argument means attempt to use the provider to create the dependency wrapped in a factory provider.
Describe alternatives you've considered
Manually creating the factories. It is not possible to create a generic factory due dotnet/extensions#478 not being implemented yet.
Additional context
https://stackoverflow.com/questions/35736070/how-to-use-funct-in-built-in-dependency-injection
This feature has been wanted for over 2 years.
rcollina, xsoheilalizadeh, RiaanVR, cobysy, adamhewitt627 and 13 more