Fusonic.Extensions.AspNetCore 9.0.0-preview.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
This is a prerelease version of Fusonic.Extensions.AspNetCore.
dotnet add package Fusonic.Extensions.AspNetCore --version 9.0.0-preview.1
NuGet\Install-Package Fusonic.Extensions.AspNetCore -Version 9.0.0-preview.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="Fusonic.Extensions.AspNetCore" Version="9.0.0-preview.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Fusonic.Extensions.AspNetCore --version 9.0.0-preview.1
#r "nuget: Fusonic.Extensions.AspNetCore, 9.0.0-preview.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.
// Install Fusonic.Extensions.AspNetCore as a Cake Addin
#addin nuget:?package=Fusonic.Extensions.AspNetCore&version=9.0.0-preview.1&prerelease

// Install Fusonic.Extensions.AspNetCore as a Cake Tool
#tool nuget:?package=Fusonic.Extensions.AspNetCore&version=9.0.0-preview.1&prerelease

ASP .Net Core Extensions

ServiceCollection extensions

services.AddAll<T>(IEnumerable<Assembly>) registers all implementing classes of T in the given assemblies.

CultureUtil

The culture util provides a simple way to get the culture from a user based on a list of supported cultures. It supports a "fallback-to-child", meaning if your application supports "de-AT" and the user only supports "de-DE", the util returns "de-AT" as the best common language.

Examples:

public class AppSettings
{
    public CultureInfo DefaultCulture { get; set; } = null!;
    public CultureInfo[] SupportedCultures { get; set; } = null!;
}

Usage:

// Supported Cultures: de-AT,en-GB
// Default: de-AT
// Header: de-AT,en-US   Result: de-AT (match)
// Header: fr-FR,en-GB   Result: de-AT (match)
// Header: de-DE,en-US   Result: de-AT (first common language)
// Header: fr-FR,en-US   Result: en-GB (first common language)
// Header: fr-FR         Result: de-AT (no match, default)
CultureUtil.FromAcceptLanguageHeader(HttpContext, appSettings.SupportedCultures, appSettings.DefaultCulture)

Ignore paths Middleware

Returns 404 for all configured paths.

This is useful if you, for example, want to avoid a SPA to handle a path. A typo in an API-Url should result in 404 and should not be handled by the SPA.

Usage:

//For example right before the SPA
app.UseIgnorePaths("/api", "/swagger", "/hangfire");

Validation of MediatR requests

MediatR requests can be validated with a simple decorator. Internally it uses the same validator that is used by ASP.NET Core for the request validation.

To enable MediatR request validation, simply add the decorator RequestValidationDecorator to IRequestHandler:

// SimpleInjector
container.RegisterDecorator(typeof(IRequestHandler<,>), typeof(RequestValidationDecorator<,>));

// Scrutor
services.Decorate(typeof(IRequestHandler<,>), typeof(RequestValidationDecorator<,>));

You can then use the System.ComponentModel-attributes and the IValidatableObject-interface for validating your models. When model validation fails, a RequestValidationException gets thrown containing all the model validation errors. You might want to handle that one in your Exception filter, if you have one.

Example:

public class GetSomething : IValidatableObject
{
    [Required]
    public string Search { get; set; }

    [Range(1, 100)]
    public int MaxResults { get; set; } = 10;

    public DateTime From { get; set; }
    public DateTime To { get; set; }

    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        if (From >= To)
            yield return new ValidationResult("From must be before To.", new[] { nameof(From), nameof(To) });
    }
}

This also works with records.

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

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Fusonic.Extensions.AspNetCore:

Package Downloads
Fusonic.Extensions.Email The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Contains common functionality for rendering email templates using razor engine and sending emails via MailKit.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.0.0-preview.1 64 4/5/2024
8.1.3 139 3/27/2024
8.1.2 93 3/27/2024
8.1.1 122 3/1/2024
8.1.0 553 1/26/2024
8.0.1 246 12/18/2023
8.0.1-rc.2 77 12/7/2023
8.0.1-rc.1 67 12/6/2023
8.0.0 290 11/21/2023
8.0.0-preview1 130 10/4/2023
7.4.0 89 1/25/2024
7.3.0 178 10/11/2023
7.2.1-rc.1 86 8/28/2023
7.2.0 515 6/28/2023
7.2.0-alpha.1 79 6/27/2023
7.1.2 402 5/25/2023
7.1.1 867 4/3/2023
7.1.1-rc.2 78 3/30/2023
7.1.1-rc.1 74 3/30/2023
7.1.0 774 2/28/2023
7.1.0-rc.1 92 2/20/2023
7.0.4-rc.5 92 2/23/2023
7.0.4-rc.4 87 2/23/2023
7.0.4-rc.3 81 2/23/2023
7.0.4-rc.2 89 2/22/2023
7.0.4-rc.1 91 2/16/2023
7.0.3 387 2/16/2023
7.0.2 268 2/9/2023
7.0.2-rc.1 101 2/2/2023
7.0.1 707 1/26/2023
7.0.0 320 1/24/2023
7.0.0-preview1 127 7/18/2022
7.0.0-beta.9 102 1/24/2023
7.0.0-beta.8 93 1/23/2023
7.0.0-beta.7 95 1/23/2023
7.0.0-beta.6 92 1/23/2023
7.0.0-beta.5 103 1/23/2023
7.0.0-beta.4 99 1/19/2023
7.0.0-beta.3 92 1/17/2023
7.0.0-beta.2 94 1/11/2023
7.0.0-beta.1 78 11/24/2022
6.2.2 14,921 9/20/2022
6.2.2-rc.1 109 9/19/2022
6.2.1 3,131 5/4/2022
6.2.0 508 4/21/2022
6.2.0-rc.2 125 4/21/2022
6.2.0-rc.1 115 4/20/2022
6.1.1 927 3/1/2022
6.1.0 593 2/10/2022
6.1.0-rc.3 114 2/10/2022
6.1.0-rc.2 106 2/10/2022
6.1.0-rc.1 119 2/9/2022
6.0.3 1,465 1/18/2022
6.0.2 3,400 1/10/2022
6.0.1 269 12/16/2021
6.0.0 774 12/13/2021
6.0.0-rc.6 155 12/6/2021
6.0.0-rc.5 329 12/6/2021
6.0.0-rc.4 505 12/6/2021
6.0.0-rc.3 375 12/6/2021
6.0.0-rc.2 349 12/6/2021
6.0.0-rc.1 650 11/15/2021
5.4.0 968 10/13/2021
5.3.0 492 9/23/2021
5.3.0-rc.1 333 9/17/2021
5.2.0 3,215 5/20/2021
5.2.0-rcjh.6 187 5/19/2021
5.2.0-rcjh.5 144 5/19/2021
5.2.0-rcjh.4 168 5/19/2021
5.2.0-rcjh.3 143 5/19/2021
5.2.0-rcjh.2 135 4/12/2021
5.2.0-rcjh.1 139 4/12/2021
5.1.3 325 5/19/2021
5.1.2 13,821 3/26/2021
5.1.1 987 1/13/2021
5.1.0 2,016 12/16/2020
5.0.0 2,463 11/17/2020
5.0.0-rc.1 263 10/15/2020
1.1.0 26,129 8/25/2020
1.0.2 619 8/19/2020
1.0.1 2,752 7/3/2020
1.0.0 472 6/15/2020