Skip to content
Simplistic Microsoft.Extensions.DependencyInjection implementation exposing a binding attribute for use with functions
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Canduits.Azure.Functions.DependencyInjection
.gitignore
Canduits.Azure.Functions.DependencyInjection.sln
LICENSE
README.md

README.md

Canduits.Azure.Functions.DependencyInjection

Simplistic Microsoft.Extensions.DependencyInjection implementation exposing a binding attribute for use with Azure Functions in NetCore 2.1

Azure Pipeline Build Status

Example usage:

Function Declaration using a defined interface

[FunctionName("ExampleFunction")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)]HttpRequest req,
ILogger log, [Inject]IExampleInterface example)
{
    example.DoSomeCoolStuff();
    return new OkResult();
}

Basic Setup in Startup.cs

using System;
using Canduits.Azure.Functions.DependencyInjection;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

[assembly: WebJobsStartup(typeof(Startup), "Startup")]
namespace my.new.function
{
    public class Startup : IWebJobsStartup
    {
        public void Configure(IWebJobsBuilder builder)
        {
            var config = new ConfigurationBuilder()
                .SetBasePath(Environment.CurrentDirectory)
                .AddJsonFile("local.settings.json", true, true)
                .AddEnvironmentVariables()
                .Build();

            builder.Services.AddLogging();

            var myNewConfig = new MyNewConfig();
            config.GetSection("MyNewConfig").Bind(myNewConfig);
            builder.Services.Configure<MyNewConfig>(config.GetSection("MyNewConfig"));

            builder.Services.AddSingleton<IExampleInterface, ExampleImplementation>();

            builder.Services.AddSingleton<InjectBindingProvider>();
            builder.AddExtension<InjectConfigProvider>();
        }
    }
}
You can’t perform that action at this time.