Skip to content

Commit

Permalink
Add a new constructor instead of modifying an existing one
Browse files Browse the repository at this point in the history
In order to avoid a binary breaking change.
  • Loading branch information
0xced committed Apr 15, 2024
1 parent 94b2ef7 commit 2fd5bcf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Linq;
using Microsoft.AspNetCore.Routing;
using System;

#if (!NETSTANDARD2_0)
using System.Linq;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Patterns;
using Microsoft.AspNetCore.Routing.Template;
#endif

using Microsoft.Extensions.DependencyInjection;
Expand All @@ -19,7 +20,11 @@ public static class SwaggerBuilderExtensions
/// </summary>
public static IApplicationBuilder UseSwagger(this IApplicationBuilder app, SwaggerOptions options)
{
#if (!NETSTANDARD2_0)
return app.UseMiddleware<SwaggerMiddleware>(options, app.ApplicationServices.GetRequiredService<TemplateBinderFactory>());
#else
return app.UseMiddleware<SwaggerMiddleware>(options);
#endif
}

/// <summary>
Expand Down
15 changes: 9 additions & 6 deletions src/Swashbuckle.AspNetCore.Swagger/SwaggerMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,22 @@ public class SwaggerMiddleware

public SwaggerMiddleware(
RequestDelegate next,
SwaggerOptions options
#if !NETSTANDARD
,TemplateBinderFactory templateBinderFactory
#endif
)
SwaggerOptions options)
{
_next = next;
_options = options ?? new SwaggerOptions();
_requestMatcher = new TemplateMatcher(TemplateParser.Parse(_options.RouteTemplate), new RouteValueDictionary());
}

#if !NETSTANDARD
public SwaggerMiddleware(
RequestDelegate next,
SwaggerOptions options,
TemplateBinderFactory templateBinderFactory) : this(next, options)
{
_templateBinder = templateBinderFactory.Create(RoutePatternFactory.Parse(_options.RouteTemplate));
#endif
}
#endif

public async Task Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
{
Expand Down

0 comments on commit 2fd5bcf

Please sign in to comment.