Dependency Injection is a must for some of us working in the dotnet core space. In ASP.NET Core, we configure our service container in
Startup.cs in the
In Azure Functions we have a similar way to do this. First thing you wanna do is to get the
Microsoft.Azure.Functions.Extensions package from NuGet. The next thing you want to do is to create a
Startup.cs class in your project. Finally, you register the assembly and inherit from the
FunctionsStartup class (from
Microsoft.Azure.Functions.Extensions.DependencyInjection) and override its Configure method, as pictured below.
Now you’re ready to use your services in your functions. In order to do so, you just inject the interface through the constructor (as we do in ASP.NET Core!).