-
-
Save justinyoo/4f4239405413c59772f0ea039ffcdeeb to your computer and use it in GitHub Desktop.
Make Your Azure WebJobs Testable Again
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 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