Provide a proper Dependency Injection story for JobHostConfiguration.
Currently, the JobHostConfiguration initialization is pretty adhoc and ends up being an 8-step process described here: https://github.com/Azure/azure-webjobs-sdk/wiki/Initialization
We need to provide a consistent natural DI story. Some requirements:
Consider leveraging new DI interfaces from .NET core. We should avoid taking a dependency on a specific DI implementation. ASP.Net does a good job of this.
I've used StructureMap and TinyIoC in the past. Currently I've skipped the DI and just new up my dependencies at the top of the functions because it was easier than setting up the DI. Definitely looking forward to seeing some changes to this.
@xt0rted we'll be sharing some additional thoughts we have around this so we can iterate and get some feedback, but the goal is to be flexible enough so you could also plug your own DI framework and address the DI pains we've been hearing about for so long. :)
@MikeStall - Could we add these details to #1036 and close this?
I've come up with a pretty easy way to get CTOR DI working for functions. Sharing it here so that others can implement it and so that the team is aware of how CTOR DI is currently achieved:
The DI Framework I use is SimpleInjector ( http://simpleinjector.readthedocs.io/en/latest/ ).
Here is a gist with code samples:
https://gist.github.com/Bio2hazard/3817ba5f291176f465baa263350925f5
A summary of what is happening:
Program.cs' Main: Initialize DI Container and pass it into a custom JobActivator
Custom JobActivator: Request class from container, check class for inheriting specific base class and register container to instantiated class.
FunctionBase: Accept container scope, implement IDisposable, dispose scope when disposed.
At this moment, managing dependencies in Azure Functions can be done in an interesting way. I've written a blog post for this:
https://devkimchi.com/2017/11/16/azure-functions-with-ioc-container/
However, IJobActivator can be something we can make use of DI for Azure Functions. Whenever I write an Azure WebJob instance, I usually use IJobActivator for DI together with Autofac like:
https://blog.kloud.com.au/2017/09/06/make-your-azure-webjobs-unit-testable-again/
Here are my NuGet packages for this:
If we can implement the IJobActivator, declare it on host.json or somewhere else, and Azure Functions runtime can detect it, it would probably be very handy for managing dependencies.
This issue is being decomposed into the following items (some of which will be further decomposed to track more concrete tasks):
Most helpful comment
This issue is being decomposed into the following items (some of which will be further decomposed to track more concrete tasks):