Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created September 5, 2017 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/4f4239405413c59772f0ea039ffcdeeb to your computer and use it in GitHub Desktop.
Save justinyoo/4f4239405413c59772f0ea039ffcdeeb to your computer and use it in GitHub Desktop.
Make Your Azure WebJobs Testable Again
public class AutofacJobActivator : WebJobActivator
{
private readonly ContainerBuilder _builder;
private IContainer _container;
public AutofacJobActivator()
{
this._builder = new ContainerBuilder();
}
public override IWebJobActivator RegisterDependencies<THandler>(THandler handler = default(THandler))
{
// Register all depdendencies here
...
if (handler != null)
{
// Perform registration with handlers here
...
}
this._container = this._builder.Build();
return this;
}
public override T CreateInstance<T>()
{
return this._container.Resolve<T>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment