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.
There are a few options available to you, the first is you can switch over to use the incredible [Lamar](https://jasperfx.github.io/lamar/getting_started/) (with it's [ASP.NET Core integration](https://jasperfx.github.io/lamar/getting_started/#sec1)).

For the most part, switching to Lamar is a few lines of code, and you'll be able to resolve `Func<>` and `Lazy<>` all day long.

I've been using it at scale for a while on a large microservices based platform and we're completely happy with it \*.

If you don't want to move over to Lamar, you can use this for resolving `Lazy<>` (sorry, I've tried and tried, and I can't get it to work with `Func<>`:

```
// Add to your Service Collection.
services.AddTransient(typeof(Lazy<>), typeof(LazyServiceFactory<>));

class LazyServiceFactory<T> : Lazy<T>
{
    public LazyServiceFactory(IServiceProvider serviceProvider)
        : base(() => serviceProvider.GetRequiredService<T>())
    {
    }
}

```

And just for completeness, here's a test too.

```
// And some tests...
[TestMethod]
[DataTestMethod]
[DataRow(ServiceLifetime.Transient)]
[DataRow(ServiceLifetime.Scoped)]
[DataRow(ServiceLifetime.Singleton)]
public void Resolve_GivenLazyilyRegisteredService_CanResolve(ServiceLifetime serviceLifetime)
{
    // Arrange
    IServiceProvider serviceProvider = CreateServiceProvider(serviceLifetime);
    using IServiceScope scope = serviceProvider.CreateScope();

    // Act
    Func<Lazy<ClassHello>> result = () => scope.ServiceProvider.GetRequiredService<Lazy<ClassHello>>();

    // Assert
    result
        .Should()
        .NotThrow()
        .And
        .Subject()
        .Value
        .Should()
        .NotBeNull();
}

static IServiceProvider CreateServiceProvider(ServiceLifetime serviceLifetime)
{
    IServiceCollection services = new ServiceCollection();

    services.Add(new ServiceDescriptor(typeof(Lazy<>), typeof(LazyServiceFactory<>), serviceLifetime));

    services.Add(new ServiceDescriptor(typeof(ClassHello), typeof(ClassHello), serviceLifetime));

    return services.BuildServiceProvider(true);
}

```

I've not put this through it's paces as I use Lamar pretty much exclusivly now, but this has come in handy for smaller/ disposable projects.

\* My only minor issue is that it doesn't support `IAsyncDisposable` [yet](https://github.com/JasperFx/lamar/issues/243).