-
-
Notifications
You must be signed in to change notification settings - Fork 34
Small tweaks to application setup #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ public static IServiceCollection AddGitHubAuthentication(this IServiceCollection | |
options.ClaimActions.MapJsonKey(GitHubAvatarClaim, "avatar_url"); | ||
} | ||
}) | ||
.ValidateOnStart() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. |
||
.Services; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah did I mix up which one is implicit? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
@@ -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(); | ||
|
||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😎