Intensity of Autofac dependencies in azure function
I think now you need to do something ugly like:
public static string MyAwesomeFunction(string message)
{
if (MyService == null)
{
var instantiator = Initialize();
MyService = instantiator.Resolve<IService>();
}
return MyService.Hello(message);
}
private static IService MyService = null;
private static IContainer Initialize()
{
// Do your IoC magic here
}
source to share
I wrote a blog post for performing dependency injection with Autofac in Azure Functions. Take a look here: Azure Function Dependency Injection with AutoFac: Autofile Features
This follows a similar approach, for example to Boris Wilhelms . Another implementation based on Boris's approach can be found on github: autofac dependency injection
source to share
While Azure Functions does not support DI out of the box, this can be added using the new extension API. You can register the container using the IExtensionConfigProvider implementation. You can find a complete example of a DI solution in Azure here https://blog.wille-zone.de/post/azure-functions-proper-dependency-injection/ .
source to share
Azure Functions does not yet support dependency injection. Follow this issue for feature request https://github.com/Azure/Azure-Functions/issues/299
source to share
You can do this using the special [inject] attribute. An example is here https://blog.wille-zone.de/post/azure-functions-proper-dependency-injection/
source to share