From an Azure Function, I want to leverage the static client proxies that I've already generated. The function will pull data from an Azure Storage Queue and commit it to the Azure SQL database through ABP EF. I have tried to leverage the code examples in the ConsoleTestApp but the code in that example doesn't work in Azure Functions. I'm using Azure Functions 4 in .NET 7.
Can you point me to any examples that demonstrate a working method?
Dan
5 Answer(s)
-
0
hi
but the code in that example doesn't work in Azure Functions
Are there any errors or anything?
-
0
The example in ConsoleTestApp creates an instance of ClientDemoService and then executes RunAsync() method. I could get that working OK within the Azure Function.
However, the problem is that in an Azure Function program.cs, you're not creating an instance of a class and executing a method in the way that it's done in the ConsoleTestApp. Instead, you're working with HostBuilder and calling Host.Run(). The methods that get called and the instantiation of the class is not done explicitly in program.cs, rather it's instantiated by the worker process (it's invoked automatically when an item is found in the Azure storage queue). So it's a very different pattern than ConsoleTestApp.
The problem, I think, has to do with dependency injection. If I don't inject the HttpApi Client App Service class, then it can't resolve it (so that is the error that I see). I can clear up that error by injecting that class in program.cs, but the moment I try to inject that class, then the worker process never instantiates my "queue processor" class - meaning it just silently fails - nothing logged. My best guess is possibly that I need to inject dependencies of the ABP HttpApi Client app service class. But I am hoping you can point me to a working example - or even to someone who's done this before.
Thanks,
Dan
-
0
hi
You have to bootstrap an abp module to use the client proxy.
You can use
AbpApplicationFactory
in your functionhttps://github.com/abpframework/abp/blob/554960d59626fc355a67f063dc6d375e3fa23844/docs/en/_deleted/Bootstrap-Modules.md#console
-
0
Ok that got me close. I'm very close to solving this. The example you provided is more for a worker process than for an isolated azure function v4 in .net 7, but it's useful and I'm almost there. I am now able to initialize the ABP app. But I get an error when I call...
_abpApplication.ServiceProvider.GetRequiredService<myAppService>();
I'm getting the following error:
Autofac.Core.Registration.ComponentNotRegisteredException: 'The requested service 'Volo.Abp.Castle.DynamicProxy.AbpAsyncDeterminationInterceptor`1[[Volo.Abp.Uow.UnitOfWorkInterceptor, Volo.Abp.Uow, Version=7.1.0.0, Culture=neutral, PublicKeyToken=null]]' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.'
-
0
hi
Please share your full code to reproduce the error. liming.ma@volosoft.com