Skip to content

Commit

Permalink
Add Middlewares to Startup Options
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmanuelthiel committed Sep 27, 2023
1 parent 0485c6e commit a9a6234
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Wemogy.AspNet/Startup/StartupExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public static void UseDefaultSetup(this IApplicationBuilder applicationBuilder,
applicationBuilder.UseAuthorization();

applicationBuilder.UseErrorHandlerMiddleware();
foreach (var middleware in options.Middlewares)
{
applicationBuilder.UseMiddleware(middleware);
}

if (options.DaprEnvironment != null)
{
Expand Down
10 changes: 10 additions & 0 deletions src/Wemogy.AspNet/Startup/StartupOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Wemogy.AspNet.Dapr;
Expand All @@ -13,9 +14,11 @@ public class StartupOptions
internal OpenApiEnvironment? OpenApiEnvironment { get; private set; }
internal MonitoringEnvironment? MonitoringEnvironment { get; private set; }
internal DaprEnvironment? DaprEnvironment { get; private set; }
internal HashSet<Type> Middlewares { get; private set; }

public StartupOptions()
{
Middlewares = new HashSet<Type>();
}

public OpenApiEnvironment AddOpenApi(string version, string? pathToXmlDocumentationFile = null)
Expand Down Expand Up @@ -53,4 +56,11 @@ public DaprEnvironment AddDapr()
DaprEnvironment = new DaprEnvironment();
return DaprEnvironment;
}

public StartupOptions AddMiddleware<TMiddleware>()
where TMiddleware : class
{
Middlewares.Add(typeof(TMiddleware));
return this;
}
}

0 comments on commit a9a6234

Please sign in to comment.