Arbeidstilsynet.Common.AspNetCore.Extensions 2.5.0

dotnet add package Arbeidstilsynet.Common.AspNetCore.Extensions --version 2.5.0
                    
NuGet\Install-Package Arbeidstilsynet.Common.AspNetCore.Extensions -Version 2.5.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Arbeidstilsynet.Common.AspNetCore.Extensions" Version="2.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Arbeidstilsynet.Common.AspNetCore.Extensions" Version="2.5.0" />
                    
Directory.Packages.props
<PackageReference Include="Arbeidstilsynet.Common.AspNetCore.Extensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Arbeidstilsynet.Common.AspNetCore.Extensions --version 2.5.0
                    
#r "nuget: Arbeidstilsynet.Common.AspNetCore.Extensions, 2.5.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Arbeidstilsynet.Common.AspNetCore.Extensions@2.5.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Arbeidstilsynet.Common.AspNetCore.Extensions&version=2.5.0
                    
Install as a Cake Addin
#tool nuget:?package=Arbeidstilsynet.Common.AspNetCore.Extensions&version=2.5.0
                    
Install as a Cake Tool

📖 Description

This package contains ASP.NET Core extension methods that provide standardized configuration and setup for web applications. It simplifies the process of configuring common middleware, services, and API conventions.

📦 Installation

dotnet add package Arbeidstilsynet.Common.AspNetCore.Extensions

🧑‍💻 Usage

Basic Setup

The package provides extension methods to quickly configure a standard ASP.NET Core web application:

var builder = WebApplication.CreateBuilder(args);

// Load your appsettings from configuration
var appSettings = builder.Configuration.GetRequired<MyAppSettings>();

// Configure standard API services
var services = builder.Services;
services.ConfigureApi();
services.ConfigureOpenTelemetry("MyAppName");
services.ConfigureSwagger();
services.AddLogging(configure =>
{
    configure.ClearProviders();
    configure.SetMinimumLevel(LogLevel.Information);
});
services.ConfigureCors(
    appSettings.API.Cors.AllowedOrigins,
    appSettings.API.Cors.AllowCredentials,
    env.IsDevelopment()
);

// Add a memory cached HTTP client
services.AddMemoryCachedHttpClient("MyCachedClient", configure =>
{
    configure.BaseAddress = new Uri("https://api.example.com");
}, cachingOptions =>
{
    cachingOptions.SlidingExpiration = TimeSpan.FromMinutes(5);
    cachingOptions.AbsoluteExpiration = TimeSpan.FromHours(1);
});

// Do the rest of your dependency injection here ...

var app = builder.Build();

// Apply standard API middleware pipeline
app.AddApi(options =>
            options.AddExceptionMapping<MyCustomException>(HttpStatusCode.NotFound)
        );
app.UseCors();
app.AddScalar();

await app.RunAsync();
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Arbeidstilsynet.Common.AspNetCore.Extensions:

Package Downloads
Arbeidstilsynet.Common.FeatureFlags

Package Description

Arbeidstilsynet.Common.Altinn

Useful methods and classes for cross-cutting concerns in Altinn applications

Arbeidstilsynet.Common.Enhetsregisteret

A http client which interfaces with enhetsregisteret (Brønnøysundregistrene)

Arbeidstilsynet.Receiver

Receive meldinger with attachments and structured data

Arbeidstilsynet.Meldinger.Data

Meldinger Data deling extensions

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.5.0 616 4/13/2026
2.5.0-alpha.8 42 4/10/2026
2.5.0-alpha.7 40 4/9/2026
2.5.0-alpha.6 47 4/9/2026
2.5.0-alpha.5 52 4/9/2026
2.5.0-alpha.4 42 4/9/2026
2.5.0-alpha.3 36 4/9/2026
2.5.0-alpha.2 39 4/9/2026
2.5.0-alpha.1 43 4/9/2026
2.4.1 987 3/26/2026
2.4.0 1,185 3/16/2026
2.3.0 2,301 3/6/2026
2.2.1 5,314 2/18/2026
2.2.1-beta1 50 2/18/2026

# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added <!-- for new features. -->

### Changed <!--  for changes in existing functionality. -->

### Deprecated <!--  for soon-to-be removed features. -->

### Removed <!-- for now removed features. -->

### Fixed <!-- for any bug fixes. -->

### Security <!-- in case of vulnerabilities. -->

## 2.5.0

### Added

- feat(auth): Added `AddStandardAuth(AuthConfiguration)` extension method for configuring Entra ID (Azure AD) JWT Bearer authentication, with a `DangerousDisableAuth` toggle for local development.
- feat(auth): Added `AuthConfiguration` record for authentication settings (`TenantId`, `ClientId`, `Scope`, `DangerousDisableAuth`).
- feat(api): Added `ConfigureStandardApi()` as a streamlined replacement for the previous `ConfigureApi()`.
- feat(api): Added `ConfigureStandardMvc()` for standalone MVC configuration (controllers, JSON options, validation filter, problem details).
- feat(api): Added `AddStandardHealthChecks()` for standalone startup health check registration.
- feat(api): Added `AddStartupChecks(StartupChecks)` to register multiple startup check groups additively, each executed in its own DI scope.
- feat(openapi): Added `AddStandardOpenApi(string appName)` with basic document info configuration.
- feat(openapi): Added `ConfigureBasicOpenApiSpec()` and `AddEntraOAuth2AndBearerSecuritySchemes()` OpenAPI document transformers.
- feat(cors): Added `CorsConfiguration` record and a new `ConfigureCors(CorsConfiguration, bool)` overload that accepts it.
- feat(api): Added `AddStandardApi(WebApplication)` middleware pipeline method that incorporates authentication, CORS, Scalar, exception handling, and health checks.

### Changed

- changed(startup): `StartupBackgroundService` now accepts multiple `StartupChecks` groups (`IEnumerable<StartupChecks>`) and runs each in its own scope.
- changed(startup): `StartupChecks` delegate signature now accepts an optional `CancellationToken` parameter.
- changed(auth): `AddAllowAllAuthorization` now logs the disabled-auth warning via the application's logging pipeline at startup instead of creating a standalone `LoggerFactory` at registration time.
- changed(api): `ConfigureStandardMvc()` now returns `IMvcBuilder` for further configuration and also configures `HttpJsonOptions` for Minimal API JSON consistency (enum-as-string, camelCase).

### Deprecated

- deprecated(api): `ConfigureApi()` — use `ConfigureStandardApi()` or register components individually instead.
- deprecated(api): `AddApi()` — use `AddStandardApi()` instead.
- deprecated(openapi): `ConfigureOpenApi()` (both overloads) — use `AddStandardOpenApi()` instead.

## 2.4.1

### Fixed

- fix(otel-config): Enhance otel config to support tracing from `ActivitySources` defined in hexarch v3.

## 2.4.0

### Added

- added(exception-handling): Added new extension method `AddExceptionMapping` to map status codes dynamically based on the exception, instead of just static mappings.

## 2.3.0

### Changed

- changed(deps): Applied minor and patch updates to dependencies

## 2.2.1

### Changed

- chore: moved package to nuget.org

## 2.2.0

### Changed

- changed(deps): Applied minor and patch updates to dependencies

## 2.1.3

### Added

- chore(aspnetcore): Use two distinct health endpoints for readiness and liveness as default (`healthz/ready` and `healthz/live`) instead of just one for all. Also, add a default `StartupHealthCheck` which can be configured to run multiple startup tasks like e.g. a database migration before it will return a healthy state.

## 2.1.2

### Fixed

- fix(scalar): Ensure scalar is using https when requested with https. Http otherwise

## 2.1.1

### Fixed

- fix(scalar): Downgrade scalar because v2.11.0 has a UI bug which leads to unexpected

## 2.1.0

### Changed

- feat(openapi): Use microsoft open api generation instead of swashbuckle

## 2.0.0

### Changed

- changed(deps): Major dotnet updated (v10)

## 1.4.2

### Changed

- chore(health-checks): Replaced simple health report (Healthy/Unhealthy) with more details for each check.

## 1.4.1

### Fixed

- fix(deps): update opentelemetry package range to support Microsoft.* v8 packages

## 1.4.0

### Changed

- fix(deps): downgraded opentelemetry packages to last version where they support Microsoft.* v8 packages

## 1.3.3

### Added

- feat(serialization): Added String-Uri serialization support (`JsonStringEnumConverter`)

## 1.3.2

### Added

- chore(extensions): add default hexarch project `Sources` for tracing. Also added ef instrumentation as default tracing instrumentation.

## 1.3.1

### Changed

- chore(renovate): all non major update

## 1.3.0

### Added

- feat(extensions): added a memory cached http client (`services.AddMemoryCachedHttpClient(name)`)

## 1.2.1

### Added

- feat(extensions): added enum to string converter as default behavior when adding controllers
- feat(extensions): added custom controller detector to also detect internal controllers (before it detected only public classes)

## 1.2.0

### Added

- feat(extensions): added extension method for adding query parameters to a Uri (`AddQueryParameters`)

## 1.1.2

### Changed

- chore(deps): update dependency swashbuckle.aspnetcore to v8

## 1.1.1

### Changed

- chore(deps): update dependency scalar.aspnetcore to v2

## 1.1.0

### Added

- Adds extension method ConfigureCors to StartupExtensions

## 1.0.0

### Changed

- refactor: applied updated project structure to project (based on `dotnet new common-package` v1.0.0)

### 0.0.3

### Removed

- Removed the ConfigureLogging method from StartupExtensions, as it was just wrapping services.AddLogging().

## 0.0.2

### Changed

- Made the extension methods more granular, instead of having a single `ConfigureApi` method, we now have separate methods for OpenTelemetry, Swagger, Logging, and Exception Handling.

## 0.0.1

Adds extension methods to consolidate ASP.NET configuration and new helpers for IConfiguration.

Cross cutting concerns are handled in a single place, including API setup,

- OpenTelemetry
- Swagger
- Logging
- Model validation
- Exception handling (mapping exceptions to HTTP responses)
- Scalar

### Added

- Introduces StartupExtensions with methods for API setup, OpenTelemetry, Swagger, logging, exception handling, and Scalar endpoints.
- Adds ConfigurationExtensions to bind and validate configuration sections with detailed error reporting.
- Supplies unit tests for service name conversion, configuration binding, exception mapping, and architecture rules; includes initial README and changelog entries.