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:"


2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team 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
    {
    
    }
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on April 11, 2025, 10:10