@@ -51,10 +51,11 @@ public void ConfigureServices(IServiceCollection services)
51
51
services . AddScoped < IFoodRepository , EfFoodRepository > ( ) ;
52
52
services . AddRouting ( options => options . LowercaseUrls = true ) ;
53
53
services . AddSingleton < IActionContextAccessor , ActionContextAccessor > ( ) ;
54
- services . AddScoped < IUrlHelper > ( implementationFactory =>
54
+ services . AddScoped < IUrlHelper > ( x =>
55
55
{
56
- var actionContext = implementationFactory . GetService < IActionContextAccessor > ( ) . ActionContext ;
57
- return new UrlHelper ( actionContext ) ;
56
+ var actionContext = x . GetRequiredService < IActionContextAccessor > ( ) . ActionContext ;
57
+ var factory = x . GetRequiredService < IUrlHelperFactory > ( ) ;
58
+ return factory . GetUrlHelper ( actionContext ) ;
58
59
} ) ;
59
60
60
61
@@ -68,8 +69,23 @@ public void ConfigureServices(IServiceCollection services)
68
69
} ) ;
69
70
70
71
services . AddVersionedApiExplorer ( o => o . GroupNameFormat = "'v'VVV" ) ;
71
- services . AddTransient < IConfigureOptions < SwaggerGenOptions > , ConfigureSwaggerOptions > ( ) ;
72
- services . AddSwaggerGen ( ) ;
72
+ services . AddSwaggerGen (
73
+ options =>
74
+ {
75
+ var provider = services . BuildServiceProvider ( )
76
+ . GetRequiredService < IApiVersionDescriptionProvider > ( ) ;
77
+
78
+ foreach ( var description in provider . ApiVersionDescriptions )
79
+ {
80
+ options . SwaggerDoc (
81
+ description . GroupName ,
82
+ new Info ( )
83
+ {
84
+ Title = $ "Sample API { description . ApiVersion } ",
85
+ Version = description . ApiVersion . ToString ( )
86
+ } ) ;
87
+ }
88
+ } ) ;
73
89
}
74
90
75
91
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -126,26 +142,4 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory,
126
142
} ) ;
127
143
}
128
144
}
129
-
130
- public class ConfigureSwaggerOptions : IConfigureOptions < SwaggerGenOptions >
131
- {
132
- readonly IApiVersionDescriptionProvider provider ;
133
-
134
- public ConfigureSwaggerOptions ( IApiVersionDescriptionProvider provider ) =>
135
- this . provider = provider ;
136
-
137
- public void Configure ( SwaggerGenOptions options )
138
- {
139
- foreach ( var description in provider . ApiVersionDescriptions )
140
- {
141
- options . SwaggerDoc (
142
- description . GroupName ,
143
- new Info ( )
144
- {
145
- Title = $ "Sample API { description . ApiVersion } ",
146
- Version = description . ApiVersion . ToString ( ) ,
147
- } ) ;
148
- }
149
- }
150
- }
151
145
}
0 commit comments