Inherit DialogService for CustomDialogService

I try to inherit the DialogSerivce:

public class DialogCustomService : DialogService
{

    public DialogCustomService(NavigationManager uriHelper, IJSRuntime jsRuntime) : base(uriHelper, jsRuntime)
    {
    }

    public async override void Close(dynamic result = null)
    {
        bool? close = await Confirm("Are you sure?", "MyTitle", new ConfirmOptions() { OkButtonText = "Yes", CancelButtonText = "No" });

        if ((bool)close)
        {
            base.Close();
        }
    }

    public async Task OpenCustomDialogAsync<TComponent>(string title = null, Dictionary<string, object> parameters = null, DialogOptions options = null) where TComponent : ComponentBase
    {
        // Add your custom logic here, if needed.

        await OpenAsync<TComponent>(title, parameters, options);
    }

But if I now call the OpenCustomDialogAsync method, the dialog wont open.
I also added my new service in the Programm.cs (builder.Services.AddScoped<DialogConfirmService>();).

Any ideas what I did wrong?

Hi @MrMaavin,

You have to replace the DialogService with your own custom one:

builder.Services.AddScoped<DialogService, DialogConfirmService>();
1 Like