Using `asp.net 5` I'd like my controller to be injected with a `Func<T>`instead of `T`

For example:

```cs
public HomeController(Func<Interfaces.IUnitOfWork> uow)

```

Instead of

```cs
public HomeController(Interfaces.IUnitOfWork uow)

```

Is it possible with the built-in DI or am I forced to move to an external DI?
['https://Stackoverflow.com/questions/35736070', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/20335/']
`Func<T>` does not get registered or resolved by default but there is nothing stopping you from registering it yourself.

e.g.

```
services.AddSingleton(provider => 
  new Func<IUnitOfWork>(() => provider.GetService<IUnitOfWork>()));

```

Note that you will also need to register IUnitOfWork itself in the usual way.
I wrote a little **extension method** that registres the service and the factory (`Func<T>`):

```cs
public static class IServiceCollectionExtension
{
    public static IServiceCollection AddFactory<TService, TServiceImplementation>(this IServiceCollection serviceCollection) 
        where TService : class
        where TServiceImplementation : class, TService
    {
        return serviceCollection
            .AddTransient<TService, TServiceImplementation>();
            .AddSingleton<Func<TService>>(sp => sp.GetRequiredService<TService>);
    }
}

```

**Usage**:

```cs
serviceCollection
   .AddFactory<IMyInterface, MyImplementation>()

```