Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dependency Injections on Azure Functions V2
public class CoreFunctionFactory : IFunctionFactory
{
private readonly IServiceProvider _container;
public CoreFunctionFactory(IModule module = null)
{
this._container = new ContainerBuilder()
.RegisterModule(module)
.Build();
}
public TFunction Create<TFunction>(ILogger log)
where TFunction : IFunction
{
// Resolve the function instance directly from the container.
var function = this._container.GetService<TFunction>();
function.Log = log;
return function;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment