diff --git a/src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/SwaggerBuilderExtensions.cs b/src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/SwaggerBuilderExtensions.cs index 1f4aa3ebeb..c973258203 100644 --- a/src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/SwaggerBuilderExtensions.cs +++ b/src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/SwaggerBuilderExtensions.cs @@ -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; @@ -19,7 +20,11 @@ public static class SwaggerBuilderExtensions /// public static IApplicationBuilder UseSwagger(this IApplicationBuilder app, SwaggerOptions options) { +#if (!NETSTANDARD2_0) + return app.UseMiddleware(options, app.ApplicationServices.GetRequiredService()); +#else return app.UseMiddleware(options); +#endif } /// diff --git a/src/Swashbuckle.AspNetCore.Swagger/SwaggerMiddleware.cs b/src/Swashbuckle.AspNetCore.Swagger/SwaggerMiddleware.cs index 40e5005c4f..66c7c346f2 100644 --- a/src/Swashbuckle.AspNetCore.Swagger/SwaggerMiddleware.cs +++ b/src/Swashbuckle.AspNetCore.Swagger/SwaggerMiddleware.cs @@ -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) {