Member-only story

Implementing Dependency Injection In Azure Functions

Shweta Lodha
3 min readFeb 28, 2022

--

This article talks about how we can use dependency injection in Azure Functions. Dependency injection is a very well known design patterns which is used to implement IoC as provides you a facility to segregate object creation logic from it’s usage.

Prerequisites And Tools Used

In order to implement dependency injection in Azure Function App, you need an active Azure subscription, Visual Studio (I’m using Visual Studio 2019) and working knowledge of C# language.

Create Function App in Visual Studio

First step is to create a new project in Visual Studio of type Azure Functions:

and select Http Trigger as shown below:

Add Classes For Dependency Injection

Next we need to add the service (classes) which we want to inject. For simplicity, we will create an interface and a class implementing that interface. This interface will have only one method named GetCurrentTime() and it will provide current time to the caller. Here are the definitions:

--

--

Shweta Lodha
Shweta Lodha

No responses yet