Starts in:
1 DAY
3 HRS
14 MIN
49 SEC
Starts in:
1 D
3 H
14 M
49 S
Open Closed

tenantRepository incejt problem in DocsMenuContributor (IMenuContributor) #3478


User avatar
0
ElifKaya created

Hello,

I need to inject tenantRepository or tenantApppService in ConfigureServices method in DocsWebModule.cs. I need to check tenant db connectionSetting before configuring menu contributor. But I can not register in ConfigureServices.

Can you give an example?

Thanks

ABP Framework version: v5.3.2

UI type: / MVC /

DB provider: EF Core

Tiered (MVC) or Identity Server Separated (Angular): yes / no

Exception message and stack trace:

Steps to reproduce the issue:"


3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    It is not recommended that you inject services inside the ConfigureServices method. The dependency injection container has not been created yet.

    I need to check tenant db connectionSetting before configuring menu contributor.

    You can inject the services in menu contributor.

    public class AbpAccountUserMenuContributor : IMenuContributor
    {
        public virtual Task ConfigureMenuAsync(MenuConfigurationContext context)
        {
          var tenantRepository = context.ServiceProvider.GetRequiredService<ITenantRepository>();
    
            return Task.CompletedTask;
        }
    }
    
    
  • User Avatar
    0
    ElifKaya created

    hi

    It is not recommended that you inject services inside the ConfigureServices method. The dependency injection container has not been created yet.

    I need to check tenant db connectionSetting before configuring menu contributor.

    You can inject the services in menu contributor.

    public class AbpAccountUserMenuContributor : IMenuContributor 
    { 
        public virtual Task ConfigureMenuAsync(MenuConfigurationContext context) 
        { 
          var tenantRepository = context.ServiceProvider.GetRequiredService<ITenantRepository>(); 
     
            return Task.CompletedTask; 
        } 
    } 
     
    

    I tried this solution first, but I get an error like this. What would be the reason?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Is your app Tiered (MVC) or Identity Server Separated?

    The app need to depend on the Saas module

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06