Starts in:
2 DAYS
4 HRS
46 MIN
31 SEC
Starts in:
2 D
4 H
46 M
31 S
Open Closed

Blazor WebAssembly Calling Application Service #5534


User avatar
0
Spospisil created
  • ABP Framework version: v7.2.2
  • UI Type: Blazor WASM
  • Database System: EF Core/PostgreSQL
  • Tiered (for MVC) or Auth Server Separated (for Angular): Tiered/Separate Auth Server

Hi,

Can you please provide me with a working sample of calling an application service from within a IMenuContributor implemented class from within a Blazor WebAssembly project? All attempts to do so does not work for me. Please do not ask me for a sample project that reproduces the issue I am having OR refer me to a link of your existing documentation. I want a working sample of a simple abp generated solution for a Blazor WASM project that successfully calls a application service from within the ConfigureMenuAsync method of a class implementing the IMenuContributor interface.

Thanks.


9 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    It's easy to do, you just need to inject the app service.

    public class MyappMenuContributor : IMenuContributor
    {
        private readonly IConfiguration _configuration;
        private readonly IIdentityUserAppService _userAppService;
    
        public MyappMenuContributor(IConfiguration configuration, IIdentityUserAppService userAppService)
        {
            _configuration = configuration;
            _userAppService = userAppService;
        }
    
        public async Task ConfigureMenuAsync(MenuConfigurationContext context)
        {
            var users = await _userAppService.GetListAsync(new GetIdentityUsersInput { MaxResultCount = 1000 });
        }
    }
    
    Configure<AbpNavigationOptions>(options =>
    {
        options.MenuContributors.Add(new MyappMenuContributor(context.Services.GetConfiguration(), context.Services.GetRequiredService<IIdentityUserAppService>()));
    });
    

  • User Avatar
    0
    Spospisil created

    Can you provide to me this sample project so I can verify you matched the exact scenario I described above? That is what I asked for and not just a screenshot of code

    Thank you

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    What's your email?

  • User Avatar
    0
    Spospisil created

    Steve@cfdatasystems.com

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Shared

  • User Avatar
    0
    Spospisil created

    Hi,

    Thank you that worked! However I'm a little confused as to why a similar ticket created by a user with a similar issue as myself did not resolve my issue. If you look at this ticket https://support.abp.io/QA/Questions/2808/how-to-user-service-injection-for-IMenuContributor you can see the suggestion is to use the context.ServiceProvider.GetRequiredService<> method do accomplish this, which is they way I was doing it (and working when my project was a MVC UI vs a Blazor Web Assembly).

    What is the difference between the two ways of achieving this and in what circumstance would I use one method of resolving over the other?

    Thanks.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    They make no difference and should both work

  • User Avatar
    0
    Spospisil created

    Clearly it did make a difference as with your way it worked for me and the other way it didn't. Spent most of the day yesterday trying to figure out why it wasn't working for me as the previous ticket created indicated.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    I don't know what's your code, but they really don't make any difference

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