Open Closed

Abp Framework #4821


User avatar
0
DominaTang created

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:"
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    You can try this:

    https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection https://github.com/junalmeida/autofac-azurefunctions

    Here 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
    {
    
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 23, 2026, 09:57
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.