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.

image.png

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?

    image.png

  • 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

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.2.0-preview. Updated on March 19, 2025, 10:09