Haithem KAROUI
Haithem KAROUI

Reputation: 1611

Dependency Injection for Azure Functions V1 DI

I have a new issue regarding the dependency injection in azure function v1.

Actual situation:

I have an azure function V1 http triggered in which I want to reference my business services the way I can use my services without reinventing the wheel. I searched on the internet and I found this interesting article from Microsoft.

However, it seems like it only works with azure function v2 (.net core) because whenever I try to install the Microsoft.Azure.Functions.Extensions, I always get the following error :

NU1107 Version conflict detected for Microsoft.Azure.WebJobs. Install/reference Microsoft.Azure.WebJobs 3.0.5 directly to project FunctionApp2365431 to resolve this issue. FunctionApp2365431 -> Microsoft.Azure.Functions.Extensions 1.0.0 -> Microsoft.Azure.WebJobs (>= 3.0.5) FunctionApp2365431 -> Microsoft.NET.Sdk.Functions 1.0.28 -> Microsoft.Azure.WebJobs (>= 2.2.0 && < 2.4.0)

Following, a comparison between the dlls of two project (one in .net core (in which i could implement DI) and the other in Net framework 461)

Comparison

You can see that versions are different, the .net core V2 azure function is 3.5 and the V1 is 2.2

I tried to reference/install manually the package version as asked in the error, and I was asked to update NewtonSoft.Json package too, I did that too, and I could after that force the installation of the Microsoft.Azure.Functions.Extensions BUT, it broke the project and I couldn’t stop getting errors.

Here is the build result after doing the steps mentioned above:

Build errors

My question here is, How can I setup DI in Net framework project eg. For Azure functions V1?

Then, Why there is only documentation for azure function V2 to setup DI?

Are V1 deprecated or is Microsoft not supporting the V1 azure functions anymore?Because this is weird!

Thanks in advance,

EDIT : My question is not a duplicate of this StackOverFlow thread because it's a complicated way and outdated comparing to the solution that Microsoft is providing for v2 azure functions.

I also watched this interesting video (still didn't test it), and the only problem here is that i want to use something provided by Microsoft (official) as for az func v2, and not the package that he has developed.

Upvotes: 2

Views: 2630

Answers (1)

Haithem KAROUI
Haithem KAROUI

Reputation: 1611

As @silent mentioned in his comment,

Here is the response from Microsoft

Regarding to your query , here is the response from Azure Function prod team :

  1. There is no plan to abandon Azure function V1 , but Azure function V2 is recommended as it will get more new features in the future .

  2. For now , DI feature is supported by Azure function V2 only , if you need this feature , maybe migrating your app from V1 to V2 will be a good idea ,and this doc will be helpful : https://learn.microsoft.com/en-us/azure/azure-functions/functions-versions#migrating-from-1x-to-2x

So the unique way to do it until now is to follow this video which is about implementing DI in Azure function V1 using AzureFunctions.Autofac package.

HK,

Upvotes: 1

Related Questions