I am wondering how to use AbpModules and Azure Function (Isolated work process, framework 4.8)
Except for change our current application module target from .Net Core 5.0 to .Net Standard 2.0:
How to resolve the DI for abp modules;
How to get access token while call App Services;
Use code to setup Current Tenant and Current User (already resolved).
Could you provide an sample code for azure function?
Thanks,
Domina Tang
If you're creating a bug/problem report, please include followings:
-
ABP Framework version: 4.1.1
-
UI type: Angular
-
DB provider: EF Core
-
Tiered (MVC) or Identity Server Separated (Angular): yes
-
Exception message and stack trace:
-
Steps to reproduce the issue:"
2 Answer(s)
-
0
Hi,
You can try this:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection
https://github.com/junalmeida/autofac-azurefunctionsHere is an example code:
public class Startup: FunctionsStartup { public override void Configure(IFunctionsHostBuilder builder) { builder.UseAutofacServiceProviderFactory(ConfigureContainer); builder.Services.AddApplication<MyProjectModule>(options => { }); var serviceProvider = builder.Services.BuildServiceProvider(); serviceProvider.GetRequiredService<IAbpApplicationWithExternalServiceProvider>().Initialize(serviceProvider); } private IContainer ConfigureContainer(ContainerBuilder builder) { // Register all functions that resides in a given namespace // The function class itself will be created using autofac builder .RegisterAssemblyTypes(typeof(Startup).Assembly) .InNamespace("MyNamespace.Functions") .AsSelf() // Azure Functions core code resolves a function class by itself. .InstancePerTriggerRequest(); // This will scope nested dependencies to each function execution builder .RegisterAssemblyTypes(typeof(Startup).Assembly) .InNamespace("MyNamespace.Services") .AsImplementedInterfaces() .InstancePerTriggerRequest(); var appContainer = builder.Build(); return appContainer; } } public class MyProjectModule : AbpModule { }
-
0
How to get access token while call App Services;
You can check this: https://github.com/abpframework/abp/blob/554960d596/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ClientDemoService.cs