adrianamalea-4040 avatar image
0 Votes"
adrianamalea-4040 asked adrianamalea-4040 commented

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


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!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SamaraSoucy-MSFT avatar image
0 Votes"
SamaraSoucy-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

adrianamalea-4040 avatar image
0 Votes"
adrianamalea-4040 answered adrianamalea-4040 commented


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=adb9793829ddae60'
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at MakeFunctionJson.AttributeExtensions.IsWebJobsAttribute(CustomAttribute attribute)
at MakeFunctionJson.ParameterInfoExtensions.<>c.<IsWebJobSdkTriggerParameter>b_0_0(CustomAttribute a)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at MakeFunctionJson.ParameterInfoExtensions.IsWebJobSdkTriggerParameter(ParameterDefinition parameterInfo)
at MakeFunctionJson.MethodInfoExtensions.<>c.<ToFunctionJson>b
_6_0(ParameterDefinition p)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at MakeFunctionJson.MethodInfoExtensions.ToFunctionJson(MethodDefinition method, String assemblyPath)
at MakeFunctionJson.FunctionJsonConverter.GenerateFunctions(IEnumerable`1 types)+MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()
Error generating functions metadata
SalesGateway.Functions C:\Users\adriana.penesel.nuget\packages\\3.0.7\build\Microsoft.NET.Sdk.Functions.Build.targets 44

Is some lib causing this? Thanks for your help!

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

adrianamalea-4040 avatar image adrianamalea-4040 SamaraSoucy-MSFT ·

Hi @SamaraSoucy-MSFT ,

Thanks for the link!
I have created a new projected, where I am trying to use [FromServices] with Microsoft.NET.Sdk.Functions" Version="3.0.13" and "Microsoft.Azure.Functions.Extensions" Version="1.1.0". I have also downgraded to Microsoft.NET.Sdk.Functions" Version="3.0.7" as @rodneyjoyce stated in the link provided by you, but still the same error.

I haven't seen any response/solution from Microsoft. Is there an incompatibility between libs, what is the combination that I should use?
If this method injection doesn't work, can you please tell me what other alternatives do I have?

Thank you and Best regards!

0 Votes 0 ·