19
19
using Microsoft . Extensions . Hosting ;
20
20
using Microsoft . OpenApi . Models ;
21
21
using Newtonsoft . Json . Serialization ;
22
+ using System . IO ;
22
23
23
24
namespace AbpCompanyName . AbpProjectName . Web . Host . Startup
24
25
{
@@ -41,10 +42,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
41
42
{
42
43
//MVC
43
44
services . AddControllersWithViews (
44
- options =>
45
- {
46
- options . Filters . Add ( new AbpAutoValidateAntiforgeryTokenAttribute ( ) ) ;
47
- }
45
+ options => { options . Filters . Add ( new AbpAutoValidateAntiforgeryTokenAttribute ( ) ) ; }
48
46
) . AddNewtonsoftJson ( options =>
49
47
{
50
48
options . SerializerSettings . ContractResolver = new AbpMvcContractResolver ( IocManager . Instance )
@@ -53,8 +51,6 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
53
51
} ;
54
52
} ) ;
55
53
56
-
57
-
58
54
IdentityRegistrar . Register ( services ) ;
59
55
AuthConfigurer . Configure ( services , _appConfiguration ) ;
60
56
@@ -79,51 +75,21 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
79
75
) ;
80
76
81
77
// Swagger - Enable this line and the related lines in Configure method to enable swagger UI
82
- services . AddSwaggerGen ( options =>
83
- {
84
- options . SwaggerDoc ( _apiVersion , new OpenApiInfo
85
- {
86
- Version = _apiVersion ,
87
- Title = "AbpProjectName API" ,
88
- Description = "AbpProjectName" ,
89
- // uncomment if needed TermsOfService = new Uri("https://example.com/terms"),
90
- Contact = new OpenApiContact
91
- {
92
- Name = "AbpProjectName" ,
93
- Email = string . Empty ,
94
- Url = new Uri ( "https://twitter.com/aspboilerplate" ) ,
95
- } ,
96
- License = new OpenApiLicense
97
- {
98
- Name = "MIT License" ,
99
- Url = new Uri ( "https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/LICENSE" ) ,
100
- }
101
- } ) ;
102
- options . DocInclusionPredicate ( ( docName , description ) => true ) ;
103
-
104
- // Define the BearerAuth scheme that's in use
105
- options . AddSecurityDefinition ( "bearerAuth" , new OpenApiSecurityScheme ( )
106
- {
107
- Description = "JWT Authorization header using the Bearer scheme. Example: \" Authorization: Bearer {token}\" " ,
108
- Name = "Authorization" ,
109
- In = ParameterLocation . Header ,
110
- Type = SecuritySchemeType . ApiKey
111
- } ) ;
112
- } ) ;
78
+ ConfigureSwagger ( services ) ;
113
79
114
80
// Configure Abp and Dependency Injection
115
81
return services . AddAbp < AbpProjectNameWebHostModule > (
116
82
// Configure Log4Net logging
117
83
options => options . IocManager . IocContainer . AddFacility < LoggingFacility > (
118
84
f => f . UseAbpLog4Net ( ) . WithConfig ( _hostingEnvironment . IsDevelopment ( )
119
- ? "log4net.config"
120
- : "log4net.Production.config"
121
- )
85
+ ? "log4net.config"
86
+ : "log4net.Production.config"
87
+ )
122
88
)
123
89
) ;
124
90
}
125
91
126
- public void Configure ( IApplicationBuilder app , ILoggerFactory loggerFactory )
92
+ public void Configure ( IApplicationBuilder app , ILoggerFactory loggerFactory )
127
93
{
128
94
app . UseAbp ( options => { options . UseAbpRequestLocalization = false ; } ) ; // Initializes ABP framework.
129
95
@@ -137,7 +103,7 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
137
103
138
104
app . UseAbpRequestLocalization ( ) ;
139
105
140
-
106
+
141
107
app . UseEndpoints ( endpoints =>
142
108
{
143
109
endpoints . MapHub < AbpCommonHub > ( "/signalr" ) ;
@@ -158,5 +124,58 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
158
124
options . DisplayRequestDuration ( ) ; // Controls the display of the request duration (in milliseconds) for "Try it out" requests.
159
125
} ) ; // URL: /swagger
160
126
}
127
+
128
+ private void ConfigureSwagger ( IServiceCollection services )
129
+ {
130
+ services . AddSwaggerGen ( options =>
131
+ {
132
+ options . SwaggerDoc ( _apiVersion , new OpenApiInfo
133
+ {
134
+ Version = _apiVersion ,
135
+ Title = "AbpProjectName API" ,
136
+ Description = "AbpProjectName" ,
137
+ // uncomment if needed TermsOfService = new Uri("https://example.com/terms"),
138
+ Contact = new OpenApiContact
139
+ {
140
+ Name = "AbpProjectName" ,
141
+ Email = string . Empty ,
142
+ Url = new Uri ( "https://twitter.com/aspboilerplate" ) ,
143
+ } ,
144
+ License = new OpenApiLicense
145
+ {
146
+ Name = "MIT License" ,
147
+ Url = new Uri ( "https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/LICENSE" ) ,
148
+ }
149
+ } ) ;
150
+ options . DocInclusionPredicate ( ( docName , description ) => true ) ;
151
+
152
+ // Define the BearerAuth scheme that's in use
153
+ options . AddSecurityDefinition ( "bearerAuth" , new OpenApiSecurityScheme ( )
154
+ {
155
+ Description =
156
+ "JWT Authorization header using the Bearer scheme. Example: \" Authorization: Bearer {token}\" " ,
157
+ Name = "Authorization" ,
158
+ In = ParameterLocation . Header ,
159
+ Type = SecuritySchemeType . ApiKey
160
+ } ) ;
161
+
162
+ //add summaries to swagger
163
+ bool canShowSummaries = _appConfiguration . GetValue < bool > ( "Swagger:ShowSummaries" ) ;
164
+ if ( canShowSummaries )
165
+ {
166
+ var hostXmlFile = $ "{ Assembly . GetExecutingAssembly ( ) . GetName ( ) . Name } .xml";
167
+ var hostXmlPath = Path . Combine ( AppContext . BaseDirectory , hostXmlFile ) ;
168
+ options . IncludeXmlComments ( hostXmlPath ) ;
169
+
170
+ var applicationXml = $ "AbpCompanyName.AbpProjectName.Application.xml";
171
+ var applicationXmlPath = Path . Combine ( AppContext . BaseDirectory , applicationXml ) ;
172
+ options . IncludeXmlComments ( applicationXmlPath ) ;
173
+
174
+ var webCoreXmlFile = $ "AbpCompanyName.AbpProjectName.Web.Core.xml";
175
+ var webCoreXmlPath = Path . Combine ( AppContext . BaseDirectory , webCoreXmlFile ) ;
176
+ options . IncludeXmlComments ( webCoreXmlPath ) ;
177
+ }
178
+ } ) ;
179
+ }
161
180
}
162
181
}
0 commit comments