diff --git a/src/TodoApp/ApiModule.cs b/src/TodoApp/ApiModule.cs index 9edab835..0ce5491c 100644 --- a/src/TodoApp/ApiModule.cs +++ b/src/TodoApp/ApiModule.cs @@ -52,7 +52,7 @@ public static IEndpointRouteBuilder MapTodoApiRoutes(this IEndpointRouteBuilder ITodoService service, CancellationToken cancellationToken) => { - if (model is null || string.IsNullOrWhiteSpace(model.Text)) + if (string.IsNullOrWhiteSpace(model.Text)) { return Results.Problem("No item text specified.", statusCode: StatusCodes.Status400BadRequest); } diff --git a/src/TodoApp/AuthenticationModule.cs b/src/TodoApp/AuthenticationModule.cs index 2b439d00..b9ce77a8 100644 --- a/src/TodoApp/AuthenticationModule.cs +++ b/src/TodoApp/AuthenticationModule.cs @@ -55,6 +55,7 @@ public static IServiceCollection AddGitHubAuthentication(this IServiceCollection options.ClaimActions.MapJsonKey(GitHubAvatarClaim, "avatar_url"); } }) + .ValidateOnStart() .Services; } diff --git a/src/TodoApp/Program.cs b/src/TodoApp/Program.cs index a47d0bd5..ad67b4db 100644 --- a/src/TodoApp/Program.cs +++ b/src/TodoApp/Program.cs @@ -14,10 +14,10 @@ builder.Services.AddSingleton(_ => SystemClock.Instance); builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddDbContext((serviceProvider, builder) => +builder.Services.AddDbContext((options) => { - var configuration = serviceProvider.GetRequiredService(); - var environment = serviceProvider.GetRequiredService(); + var configuration = builder.Configuration; + var environment = builder.Environment; var dataDirectory = configuration["DataDirectory"]; if (string.IsNullOrEmpty(dataDirectory) || !Path.IsPathRooted(dataDirectory)) @@ -27,7 +27,7 @@ var databaseFile = Path.Combine(dataDirectory, "TodoApp.db"); - builder.UseSqlite("Data Source=" + databaseFile); + options.UseSqlite("Data Source=" + databaseFile); }); // Add user authentication with GitHub as an external OAuth provider @@ -35,7 +35,6 @@ // Add Razor Pages to render the UI builder.Services.AddRazorPages(); -builder.Services.AddRouting(); // Configure OpenAPI documentation for the Todo API builder.Services.AddEndpointsApiExplorer(); @@ -62,17 +61,20 @@ // Add static files for JavaScript, CSS and OpenAPI app.UseStaticFiles(); +// We explicitly call UseRouting here because of https://github.com/dotnet/aspnetcore/issues/34146 +app.UseRouting(); + // Add authN for GitHub app.UseAuthentication(); app.UseAuthorization(); +// Add Swagger endpoint for OpenAPI +app.UseSwagger(); + // Add the HTTP endpoints app.MapAuthenticationRoutes(); app.MapTodoApiRoutes(); -// Add Swagger endpoint for OpenAPI -app.UseSwagger(); - // Add Razor Pages for the UI app.MapRazorPages();