BorisWilhelms / azure-function-dependency-injection

Dependency Injection for Azure Functions v2
https://blog.wille-zone.de/
MIT License
145 stars 45 forks source link

Access to IConfigurationRoot when registering services #3

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi Boris,

Thanks for the code and useful blog post.

When I register some services, I need to be able to use a connection string from a configuration object. I found a good article by Jon Gallant that describes the new way to build an IConfigurationRoot object. However, that approach relies on a ExecutionContext object, which I don't is available in InjectConfiguration.

Do you have any ideas how a can do this?

daulet commented 6 years ago

I've had a similar need and ended up creating [Inject] binding that would automatically inject IConfiguration instance that you can use to read all application settings, including connection strings. Working example:

https://github.com/daulet/Indigo.Functions/blob/master/sample/AutofacFunctionSample/ICacheConfigProvider.cs

BorisWilhelms commented 6 years ago

Hi,

I have updated the library to Azure Functions V2. It is now possible to access the configuration when configuring the IoC container. See the readme for an example.