Is it possible to switch Azure functions standard DI container for another?

361 Views Asked by At

Currently I am using DI in azure functions the standard way


public class Startup : FunctionsStartup
{
    public override void Configure(IFunctionsHostBuilder builder)
    {
       /*Register dependencies*/
    }
}

(Microsoft.Azure.Functions.Extensions.DependencyInjection.FunctionsStartup)


Is it possible to switch to https://github.com/dadhi/DryIoc container while still being able to use DI to resolve dependencies through constructor of azure functions? If so, how?

2

There are 2 best solutions below

0
Štěpán U. On

So the answer to my question is that it is possible. But it requires implementing custom IJobActivatorEx and IJobActivator. And then replace it in IServiceCollection.

hostBuilder.Services.Replace( ServiceDescriptor.Singleton(typeof(IJobActivator), typeof(ScopedJobActivator)));
hostBuilder.Services.Replace( ServiceDescriptor.Singleton(typeof(IJobActivatorEx), typeof(ScopedJobActivator)));

I found this implementation in Autofac container extension https://github.com/junalmeida/autofac-azurefunctions in class ConfigurationExtensions

Sadly, I don't yet have working implementation for DryIoc.

0
dadhi On