Arbeidstilsynet.Common.AspNetCore.Extensions 2.2.1

dotnet add package Arbeidstilsynet.Common.AspNetCore.Extensions --version 2.2.1
                    
NuGet\Install-Package Arbeidstilsynet.Common.AspNetCore.Extensions -Version 2.2.1
                    
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.2.1" />
                    
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.2.1" />
                    
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.2.1
                    
#r "nuget: Arbeidstilsynet.Common.AspNetCore.Extensions, 2.2.1"
                    
#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.2.1
                    
#: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.2.1
                    
Install as a Cake Addin
#tool nuget:?package=Arbeidstilsynet.Common.AspNetCore.Extensions&version=2.2.1
                    
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 (4)

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

Package Downloads
Arbeidstilsynet.Common.FeatureFlags

Package Description

Arbeidstilsynet.Common.Enhetsregisteret

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

Arbeidstilsynet.Common.Altinn

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

Arbeidstilsynet.Common.GeoNorge

Implements a client which integrates with https://ws.geonorge.no/.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.1 1,275 2/18/2026
2.2.1-beta1 43 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.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.