-
-
Save justinyoo/7c94feb6d258c451130afaec2fd3ebee to your computer and use it in GitHub Desktop.
Azure Functions with IoC Container
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 FunctionFactory : IFunctionFactory | |
{ | |
private readonly IContainer _container; | |
public FunctionFactory(RegistrationHandler handler = null) | |
{ | |
// Create the Autofac container directly from | |
// Autofac container builder. | |
this._container = new ContainerBuilder() | |
.RegisterModule<AppModule>(handler) | |
.Build(); | |
} | |
public TFunction Create<TFunction>(TraceWriter log) | |
where TFunction : IFunction | |
{ | |
// Resolve the function instance directly from the container. | |
var function = this._container.Resolve<TFunction>(); | |
function.Log = log; | |
return function; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment