DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,503 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cesar Codes
Cesar Codes

Posted on

Dependency Injection in Azure Functions

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 ConfigureServices.

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!).

Happy Coding!

Top comments (0)

🌚 Life is too short to browse without dark mode