File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
examples/net8.0/aspnetcore Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 1010using StackExchange . Redis ;
1111
1212var builder = WebApplication . CreateBuilder ( args ) ;
13+
1314builder . Services . AddOpenTelemetry ( )
1415 . WithLogging ( builder => builder . AddOtlpExporter ( ) )
1516 . WithMetrics ( builder => builder . UseGrafana ( ) )
1617 . WithTracing ( builder => builder . UseGrafana ( ) . AddConsoleExporter ( ) ) ;
1718
1819// Redis
19- builder . Services . AddSingleton < IConnectionMultiplexer > (
20- sp => ConnectionMultiplexer . Connect ( "redis:6379" ) ) ;
21- builder . Services . AddScoped (
22- sp => sp . GetRequiredService < IConnectionMultiplexer > ( ) . GetDatabase ( ) ) ;
20+ builder . Services . AddSingleton < IConnectionMultiplexer > ( sp => ConnectionMultiplexer . Connect ( "redis:6379" ) ) ;
21+ builder . Services . AddScoped ( sp => sp . GetRequiredService < IConnectionMultiplexer > ( ) . GetDatabase ( ) ) ;
2322
24- // MSSQL
23+ // Microsoft SQL Server
2524builder . Services . AddTransient ( sp =>
2625{
2726 var connectionString = "Server=mssql,1433;Database=master;User=sa;Password=Password12345%%;Encrypt=False;TrustServerCertificate=True" ;
2827 return new SqlConnection ( connectionString ) ;
2928} ) ;
3029
3130builder . Services . AddControllers ( ) ;
31+
3232// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
3333builder . Services . AddEndpointsApiExplorer ( ) ;
3434builder . Services . AddSwaggerGen ( ) ;
3535
3636var app = builder . Build ( ) ;
37+
3738app . UseSwagger ( ) ;
3839app . UseSwaggerUI ( ) ;
40+
3941app . UseAuthorization ( ) ;
4042app . MapControllers ( ) ;
43+
4144app . MapGet ( "/" , ( ) => Results . Redirect ( "/swagger" ) ) ;
45+
4246app . Run ( ) ;
You can’t perform that action at this time.
0 commit comments