Azure Functions v2 migrated to v3 how to replace the custom dependency injection lib

adriana_malea 141 Reputation points


For dependency injection in Azure functions v2, this lib is used in my project: 'Willezone.Azure.WebJobs.Extensions.DependencyInjection'.
For the migration to v3, how did you proceed with the injection?
I know that Azure Function v3 with DI is possible, but this means lots of changes in our current project and I'm not aware of the whole impact.
So, my question is: if you have used the custom lib for DI in v2, have you replaced it with the standard DI libs from v3 and works fine?
Thank you!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,363 questions
0 comments No comments
{count} votes

Accepted answer
  1. Samara Soucy - MSFT 5,051 Reputation points

    If you are updating to v3 with .NET Core 3.1 I can't guarantee there won't be any issues, but from a quick look at the library I don't see anything that would definitely cause problems- the process is fairly similar between the two. I would still suggest creating a test environment set to v3 and verify everything works as expected.

    If you are moving to the latest v3 with .NET 5, then I would anticipate that you will need to make some changes to your code, and moving to the built-in DI may be your best option. Both the way DI and how bindings work (how it appears this library actually does the injection) have changed quite a bit.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. adriana_malea 141 Reputation points


    Yes, I have upgrade to v3 with .NET Core 3.1. I have replaced all the [Inject] from Willezone lib with [FromServices], because I needed method injection.

    I use the following libs:
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.18" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.6" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.8.7" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.2" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.7" />
    <PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="1.5.4" />
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.6.0" />
    <PackageReference Include="Azure.Storage.Queues" Version="12.6.0" />
    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />

    But unfortunately I got this build error, that I don't know how to solve:
    Error Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.AspNetCore.Mvc.Core, Version=, Culture=neutral, PublicKeyToken=....
    at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)

    Is some lib causing this? Thanks for your help!