- ABP Framework version: v5.1.4
- UI type: Angular / MVC
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): yes
For the Web.Public MVC Project, we require certain menu items are available/unavailable based on the state of the user. I think the right approach is to use DI to inject the interface for the application service I want to use to get the data.
However, I can't add the interface to the constructor of the MenuContributor class because it would be required in the module class itself:
I've read the dependency injection section of the guide and think that I should be using property injection but it's not clear to me how I can get an instance of the interface: https://docs.abp.io/en/abp/5.2/Dependency-Injection#property-injection
Can you please provide some guidance on how to achieve this?
Thanks
2 Answer(s)
-
0
MenuContributor will be triggered with
MenuConfigurationContext
and it containsServiceProvider
as a property. You can resolve any service by using it:public async Task ConfigureMenuAsync(MenuConfigurationContext context) { var userTaskPublicAppService = context.ServiceProvider.GetRequiredService<IUserTaskPublicAppService>(); }
-
0
Worked a charm!
Thanks so much.