Dependency Injections on Azure Functions V2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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