Skip to content

Commit

Permalink
Minor improvements to user notification exception middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Jun 28, 2024
1 parent b751463 commit 4ee81a3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Shiny.Mediator.Maui/MauiMediatorExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Shiny.Mediator.Maui;
using Shiny.Mediator.Middleware;

Expand All @@ -7,6 +8,13 @@ namespace Shiny.Mediator;

public static class MauiMediatorExtensions
{
public static void RunInBackground(this Task task, ILogger errorLogger)
=> task.ContinueWith(x =>
{
if (x.Exception != null)
errorLogger.LogError(x.Exception, "Fire & Forget trapped error");
}, TaskContinuationOptions.OnlyOnFaulted);

/// <summary>
/// Adds Maui Event Collector to mediator
/// </summary>
Expand All @@ -22,9 +30,11 @@ public static ShinyConfigurator UseMaui(this ShinyConfigurator cfg, bool include
cfg.AddEventExceptionHandlingMiddleware();
cfg.AddMainThreadEventMiddleware();

cfg.AddUserNotificationExceptionMiddleware();
cfg.AddTimedMiddleware();
cfg.AddOfflineAvailabilityMiddleware();
// cfg.AddUserNotificationExceptionMiddleware();

cfg.AddReplayStreamMiddleware();
}
return cfg;
}
Expand Down Expand Up @@ -61,9 +71,9 @@ public static ShinyConfigurator AddReplayStreamMiddleware(this ShinyConfigurator
}


public static ShinyConfigurator AddUserNotificationExceptionMiddleware(this ShinyConfigurator cfg, UserExceptionRequestMiddlewareConfig config)
public static ShinyConfigurator AddUserNotificationExceptionMiddleware(this ShinyConfigurator cfg, UserExceptionRequestMiddlewareConfig? config = null)
{
cfg.Services.AddSingleton(config);
cfg.Services.AddSingleton(config ?? new());
cfg.AddOpenRequestMiddleware(typeof(UserExceptionRequestMiddleware<,>));
return cfg;
}
Expand Down

0 comments on commit 4ee81a3

Please sign in to comment.