Create a gist now

Instantly share code, notes, and snippets.

@justinyoo /FunctionFactory.cs Secret
Last active Nov 15, 2017

What would you like to do?
Azure Functions with IoC Container
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