feat(AspNetCore): increase granularity of startup extensions + OpenApi and Authorization#167
feat(AspNetCore): increase granularity of startup extensions + OpenApi and Authorization#167
Conversation
…sions and services
There was a problem hiding this comment.
Pull request overview
This PR increases the granularity of the ASP.NET Core startup/service-registration extensions and adds first-class OpenAPI + authorization/authentication helpers (including Entra ID support).
Changes:
- Split the existing “configure API” setup into smaller, composable service-registration methods (standard MVC + health checks + startup checks).
- Add OpenAPI extension helpers (basic spec metadata + Entra OAuth2/Bearer scheme wiring).
- Introduce
AuthConfiguration+ standard auth registration methods and update startup checks execution to support multiple groups/scopes.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| AspNetCore/AT.Common.AspNetCore.Publish/Extensions/StartupExtensions.cs | Refactors API setup into more granular extension methods; adds standard OpenAPI + auth helpers; marks old APIs obsolete. |
| AspNetCore/AT.Common.AspNetCore.Publish/Extensions/OpenApiExtensions.cs | New OpenAPI option transformers for basic metadata + Entra security schemes. |
| AspNetCore/AT.Common.AspNetCore.Publish/CrossCutting/StartupBackgroundService.cs | Updates startup task execution to support multiple StartupChecks registrations with separate scopes. |
| AspNetCore/AT.Common.AspNetCore.Publish/CrossCutting/AuthConfiguration.cs | New configuration record for Entra/JWT settings + disable-auth flag. |
| AspNetCore/AT.Common.AspNetCore.Publish/AT.Common.AspNetCore.Publish.csproj | Adds JwtBearer package dependency to support Entra/JWT auth. |
Comments suppressed due to low confidence (3)
AspNetCore/AT.Common.AspNetCore.Publish/Extensions/StartupExtensions.cs:77
ConfigureStandardApi()already callsAddStandardHealthChecks(), which registersStartupHealthCheckand adds a health check named "Startup". Re-registering the same singleton and adding the same named health check here risks duplicate health check entries (often causing runtime failures when building the health report dictionary). Remove the duplicateAddSingleton<StartupHealthCheck>()/.AddCheck<StartupHealthCheck>("Startup")from this obsolete method and only callservices.AddHealthChecks()forbuildHealthChecksActionif needed.
{
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
options.JsonSerializerOptions.Converters.Add(new JsonStringUriConverter());
});
AspNetCore/AT.Common.AspNetCore.Publish/Extensions/StartupExtensions.cs:288
- The obsolete message says "Use AddBasicOpenApi instead." but this PR introduces
AddStandardOpenApi(...)(and noAddBasicOpenApiexists here). Update the obsolete guidance to point to the correct replacement method to avoid broken migration instructions.
})
.WithLogging(
logging =>
{
logging.AddOtlpExporter();
AspNetCore/AT.Common.AspNetCore.Publish/Extensions/StartupExtensions.cs:418
- This logging code likely won’t compile as-is:
IAssemblyInfois declared in namespaceArbeidstilsynet.Common.AspNetCore(seeIAssemblyInfo.cs) and isn’t in scope here, soCreateLogger<IAssemblyInfo>()is unresolved. Also, creating a newLoggerFactorywithAddConsole()bypasses the host’s configured logging pipeline and can cause unexpected console output in consuming apps. Prefer logging via DI at runtime (e.g., from a hosted service/startup filter) or remove the log here; if you keep it, use an in-scope category type (e.g.,StartupExtensions) and the app’sILoggerFactory/ILogger<T>instead of creating a new factory. (Also the message referencesAuthenticationConfiguration, but the type isAuthConfiguration.)
else if (allowedOrigins != null && allowedOrigins.Length > 0)
{
policy.WithOrigins(allowedOrigins).AllowAnyMethod().AllowAnyHeader();
if (allowCredentials)
{
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
AspNetCore/AT.Common.AspNetCore.Publish/Extensions/StartupExtensions.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
AspNetCore/AT.Common.AspNetCore.Publish/Extensions/StartupExtensions.cs
Outdated
Show resolved
Hide resolved
AspNetCore/AT.Common.AspNetCore.Publish/Extensions/StartupExtensions.cs
Outdated
Show resolved
Hide resolved
AspNetCore/AT.Common.AspNetCore.Publish/CrossCutting/StartupBackgroundService.cs
Show resolved
Hide resolved
|



No description provided.