1
1
using System . Reflection ;
2
- using Microsoft . AspNetCore . Mvc ;
3
- using Microsoft . AspNetCore . Mvc . Versioning ;
2
+ using Asp . Versioning ;
4
3
using Microsoft . Extensions . Http ;
5
4
using Microsoft . Extensions . Internal ;
6
5
using Microsoft . OpenApi . Models ;
7
6
using Npgsql ;
8
- using OpenTelemetry ;
9
7
using OpenTelemetry . Resources ;
10
8
using OpenTelemetry . Trace ;
11
9
using Prometheus ;
12
- using Prometheus . DotNetRuntime ;
13
10
using QuickstartTemplate . ApplicationCore ;
14
11
using QuickstartTemplate . ApplicationCore . Resources ;
15
12
using QuickstartTemplate . Infrastructure ;
16
13
using QuickstartTemplate . Infrastructure . Common ;
17
14
using QuickstartTemplate . Infrastructure . DbContexts ;
18
15
using Serilog ;
19
16
using Serilog . HttpClient . Extensions ;
20
- using StackExchange . Redis ;
21
17
22
18
namespace QuickstartTemplate . WebApi ;
23
19
@@ -26,49 +22,44 @@ public class Startup
26
22
public Startup ( IConfiguration configuration )
27
23
{
28
24
_configuration = configuration ;
29
-
30
- _connectionMultiplexer = ! string . IsNullOrEmpty ( _configuration . GetConnectionString ( "Redis" ) )
31
- ? ConnectionMultiplexer . Connect ( _configuration . GetConnectionString ( "Redis" ) )
32
- : null ;
33
25
}
34
26
35
27
private readonly IConfiguration _configuration ;
36
28
37
- private readonly IConnectionMultiplexer ? _connectionMultiplexer ;
38
-
39
29
public void ConfigureServices ( IServiceCollection services )
40
30
{
41
31
services . AddLocalization ( ) ;
42
32
43
33
services . AddControllers ( )
44
34
. AddDataAnnotationsLocalization ( options =>
45
35
{
46
- options . DataAnnotationLocalizerProvider = ( type , factory ) =>
36
+ options . DataAnnotationLocalizerProvider = ( _ , factory ) =>
47
37
factory . Create ( typeof ( SharedResource ) ) ;
48
38
} ) ;
49
39
50
- services . AddCors ( crosOption =>
40
+ services . AddCors ( corsOption =>
51
41
{
52
- crosOption . AddDefaultPolicy (
42
+ corsOption . AddDefaultPolicy (
53
43
builder => builder . AllowAnyOrigin ( )
54
44
. AllowAnyMethod ( )
55
45
. AllowAnyHeader ( )
56
46
. SetPreflightMaxAge ( TimeSpan . FromMinutes ( 10 ) ) ) ;
57
47
} ) ;
58
48
59
49
services . AddApiVersioning ( o =>
60
- {
61
- o . AssumeDefaultVersionWhenUnspecified = false ;
62
- o . DefaultApiVersion = new ApiVersion ( 1 , 0 ) ;
63
- o . ReportApiVersions = true ;
64
- o . ApiVersionReader = new UrlSegmentApiVersionReader ( ) ;
65
- } ) ;
66
-
67
- if ( _connectionMultiplexer is null )
68
- services . AddDistributedMemoryCache ( ) ;
69
- else
70
- services . AddStackExchangeRedisCache ( options =>
71
- options . ConnectionMultiplexerFactory = async ( ) => _connectionMultiplexer ) ;
50
+ {
51
+ o . AssumeDefaultVersionWhenUnspecified = false ;
52
+ o . DefaultApiVersion = new ApiVersion ( 1 , 0 ) ;
53
+ o . ReportApiVersions = true ;
54
+ o . ApiVersionReader = new UrlSegmentApiVersionReader ( ) ;
55
+ } )
56
+ . AddMvc ( )
57
+ . AddApiExplorer (
58
+ options =>
59
+ {
60
+ options . GroupNameFormat = "'v'VVV" ;
61
+ options . SubstituteApiVersionInUrl = true ;
62
+ } ) ;
72
63
73
64
services . AddAuthentication ( "Bearer" )
74
65
// JWT tokens (default scheme)
@@ -109,29 +100,23 @@ public void ConfigureServices(IServiceCollection services)
109
100
services . AddInfrastructure ( _configuration ) ;
110
101
services . AddApplication ( ) ;
111
102
112
- // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
113
- services . AddVersionedApiExplorer ( options =>
114
- {
115
- options . GroupNameFormat = "'v'VVV" ;
116
- options . SubstituteApiVersionInUrl = true ;
117
- } ) ;
118
-
103
+ services . AddEndpointsApiExplorer ( ) ;
119
104
services . AddSwaggerGen ( options =>
120
105
{
121
- options . SwaggerDoc ( "v1" , new OpenApiInfo ( )
106
+ options . SwaggerDoc ( "v1" , new ( )
122
107
{
123
108
Title = "v1" ,
124
109
Version = "v1"
125
110
} ) ;
126
- options . SwaggerDoc ( "v2" , new OpenApiInfo ( )
111
+ options . SwaggerDoc ( "v2" , new ( )
127
112
{
128
113
Title = "v2" ,
129
114
Version = "v2"
130
115
} ) ;
131
116
132
117
//Locate the XML file being generated by ASP.NET...
133
- var xmlFile = $ "{ Assembly . GetExecutingAssembly ( ) . GetName ( ) . Name } .xml";
134
- var xmlPath = Path . Combine ( AppContext . BaseDirectory , xmlFile ) ;
118
+ string xmlFile = $ "{ Assembly . GetExecutingAssembly ( ) . GetName ( ) . Name } .xml";
119
+ string xmlPath = Path . Combine ( AppContext . BaseDirectory , xmlFile ) ;
135
120
//... and tell Swagger to use those XML comments.
136
121
options . IncludeXmlComments ( xmlPath ) ;
137
122
@@ -186,9 +171,6 @@ public void ConfigureServices(IServiceCollection services)
186
171
builder . AddHttpClientInstrumentation ( ) ;
187
172
builder . AddEntityFrameworkCoreInstrumentation ( options => options . SetDbStatementForText = true ) ;
188
173
builder . AddNpgsql ( ) ;
189
-
190
- if ( _connectionMultiplexer is not null )
191
- builder . AddRedisInstrumentation ( _connectionMultiplexer , options => options . SetVerboseDatabaseStatements = true ) ;
192
174
} ) ;
193
175
194
176
#if ! DEBUG //https://github.com/djluck/prometheus-net.DotNetRuntime/issues/34
0 commit comments