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

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

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

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

    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 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.