Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/TodoApp/ApiModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new in rc1, we use the nullability of the parameter to determine if we should call your method with null. dotnet/aspnetcore#32375

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of nice little QoL and usability stuff coming in now 😎

{
return Results.Problem("No item text specified.", statusCode: StatusCodes.Status400BadRequest);
}
Expand Down
1 change: 1 addition & 0 deletions src/TodoApp/AuthenticationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static IServiceCollection AddGitHubAuthentication(this IServiceCollection
options.ClaimActions.MapJsonKey(GitHubAvatarClaim, "avatar_url");
}
})
.ValidateOnStart()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

.Services;
}

Expand Down
18 changes: 10 additions & 8 deletions src/TodoApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
builder.Services.AddSingleton<IClock>(_ => SystemClock.Instance);
builder.Services.AddScoped<ITodoRepository, TodoRepository>();
builder.Services.AddScoped<ITodoService, TodoService>();
builder.Services.AddDbContext<TodoContext>((serviceProvider, builder) =>
builder.Services.AddDbContext<TodoContext>((options) =>
{
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
var environment = serviceProvider.GetRequiredService<IHostEnvironment>();
var configuration = builder.Configuration;
var environment = builder.Environment;
var dataDirectory = configuration["DataDirectory"];

if (string.IsNullOrEmpty(dataDirectory) || !Path.IsPathRooted(dataDirectory))
Expand All @@ -27,15 +27,14 @@

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
builder.Services.AddGitHubAuthentication();

// Add Razor Pages to render the UI
builder.Services.AddRazorPages();
builder.Services.AddRouting();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah did I mix up which one is implicit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this is implicit


// Configure OpenAPI documentation for the Todo API
builder.Services.AddEndpointsApiExplorer();
Expand All @@ -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();

Expand Down