HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.45k stars 1.71k forks source link

Use Hangfire Dashboard in Maui App #2096

Open Ewerton opened 2 years ago

Ewerton commented 2 years ago

I'am developing a .Net Maui Blazor App and wanted to use the hangfire dashboard in it. My attempt was to start the dashboard and show it inside and iframe in my blazor Component.

I 'cant make it work because in Maui App the Program.cs has the following MauiAppBuilder builder = MauiApp.CreateBuilder(); and the samples in Hangfire docs shows that I need an aspnet core WebApp, which uses the following WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

Since the builders are different, the hangfire middlewares cant be used.

Is there a way to workaround it?

meriturva commented 2 years ago

You have to start two different host for example:

public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            CreateHostBuilder().Build().RunAsync();

            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>();

            return builder.Build();
        }

        public static IHostBuilder CreateHostBuilder() =>
           Host.CreateDefaultBuilder()
               .ConfigureWebHostDefaults(webBuilder =>
               {
                   webBuilder.UseStartup<Startup>();
                   webBuilder.UseUrls("http://localhost:5003");
               });
    }

see CreateHostBuilder().Build().RunAsync();