refactored program.cs to have more of a fluent like syntax
This commit is contained in:
+7
-10
@@ -27,17 +27,14 @@ if (args.Length == 2 && args[0].ToLower() == "seed")
|
||||
}
|
||||
else
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var app = WebApplication
|
||||
.CreateBuilder(args)
|
||||
.SetupDb()
|
||||
.SetupMvC()
|
||||
.SetupSwagger()
|
||||
.Build();
|
||||
|
||||
Services.SetupDb(builder);
|
||||
Services.SetupMvC(builder);
|
||||
Services.SetupSwagger(builder);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
Middleware.Setup(app);
|
||||
|
||||
app.Run();
|
||||
app.SetupMiddleware().Run();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace server.Setup
|
||||
{
|
||||
public static class Middleware
|
||||
{
|
||||
public static void Setup(WebApplication app)
|
||||
public static WebApplication SetupMiddleware(this WebApplication app)
|
||||
{
|
||||
app.UseSwagger(options =>
|
||||
{
|
||||
@@ -36,6 +36,8 @@ namespace server.Setup
|
||||
app.MapControllers();
|
||||
|
||||
app.UseIpRateLimiting();
|
||||
|
||||
return app;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace server.Setup
|
||||
{
|
||||
public static class Services
|
||||
{
|
||||
public static void SetupDb(WebApplicationBuilder builder)
|
||||
public static WebApplicationBuilder SetupDb(this WebApplicationBuilder builder)
|
||||
{
|
||||
builder.Services.Configure<DatabaseSettings>(
|
||||
builder.Configuration.GetSection("MongoDBSettings"));
|
||||
@@ -29,9 +29,11 @@ namespace server.Setup
|
||||
builder.Services.AddScoped<IQuoteRepository, QuoteRepository>();
|
||||
|
||||
builder.Services.AddScoped<ICharacterRepository, CharacterRepository>();
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static void SetupMvC(WebApplicationBuilder builder)
|
||||
public static WebApplicationBuilder SetupMvC(this WebApplicationBuilder builder)
|
||||
{
|
||||
builder.Services.AddMemoryCache();
|
||||
|
||||
@@ -61,9 +63,11 @@ namespace server.Setup
|
||||
{
|
||||
config.GroupNameFormat = "'v'VVV";
|
||||
});
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static void SetupSwagger(WebApplicationBuilder builder)
|
||||
public static WebApplicationBuilder SetupSwagger(this WebApplicationBuilder builder)
|
||||
{
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
@@ -75,6 +79,8 @@ namespace server.Setup
|
||||
});
|
||||
|
||||
builder.Services.ConfigureOptions<ConfigureSwaggerOptions>();
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user