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/']
As far as I'm aware deferring dependencies like this isn't possible using the current default IoC container within ASP.NET Core. I've not been able to get it working anyway!

To defer the initialisation of dependencies like this you'll need to implement an existing, more feature rich IoC container.
I have solution below

```cs
    public static IServiceCollection WithFunc<TService>(this IServiceCollection serviceCollection) where TService : class {
        var serviceType = typeof(TService);
        var serviceDescriptor = serviceCollection.LastOrDefault(x => x.ServiceType == serviceType);
        Debug.Assert(serviceDescriptor != null);
        serviceCollection.Add(ServiceDescriptor.Describe(typeof(Func<TService>),
            scope => new Func<TService>(scope.GetRequiredService<TService>),
            serviceDescriptor.Lifetime));
        return serviceCollection;
    }

```

usage

```cs
[Fact]
void with_func() {
    var services = new ServiceCollection()
        .AddTransient<IFoo, Foo>().WithFunc<IFoo>()
        .BuildServiceProvider();
    var fooFunc = services.GetRequiredService<Func<IFoo>>();
    Assert.NotNull(fooFunc);
}

```

more detail in gist <https://gist.github.com/leoninew/d2f174fe1422e453c60fb78e69342310>