https://github.com/stofte/azurefunctions-simpledependencyinjection
Basic Dependency Injection for Azure Functions v2
https://github.com/stofte/azurefunctions-simpledependencyinjection
azure azure-functions dependency-injection
Last synced: about 2 months ago
JSON representation
Basic Dependency Injection for Azure Functions v2
- Host: GitHub
- URL: https://github.com/stofte/azurefunctions-simpledependencyinjection
- Owner: stofte
- License: mit
- Created: 2018-07-30T09:18:25.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-01-21T14:35:43.000Z (over 7 years ago)
- Last Synced: 2025-08-13T18:08:57.674Z (10 months ago)
- Topics: azure, azure-functions, dependency-injection
- Language: C#
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
Azure Functions v2 Simple Dependency Injection
==============================================
[Note: v2 function runtimes only](https://docs.microsoft.com/en-us/azure/azure-functions/functions-versions)
Packaged code based on [Boris Wilhelms code](https://blog.wille-zone.de/post/azure-functions-proper-dependency-injection/). A basic configuration interface has been added to enable packaging. The code expects a single implementation of this interface. The container configuration is shared by all functions in the app. This package requires `3.0.3` of the `Microsoft.Azure.WebJobs` package.
Configuration example:
using AzureFunctions.Extensions.SimpleDependencyInjection;
namespace MyFunctionApp
{
public class Startup : IContainerConfigurator
{
// IContainerConfigurator interface
public void Configure(IServiceCollection services)
{
// supports basic registrations+scoped (as in article)
services.AddSingleton(new FooService());
}
}
}
Usage example:
public static class MyFunction
{
[FunctionName("MyFunction")]
public static async Task Run(
[TimerTrigger("%myfunctimer%")] TimerInfo myTimer,
[Inject] FooService fooSvc
)
{
}
}