Fusonic.Extensions.AspNetCore
9.5.0
Prefix Reserved
dotnet add package Fusonic.Extensions.AspNetCore --version 9.5.0
NuGet\Install-Package Fusonic.Extensions.AspNetCore -Version 9.5.0
<PackageReference Include="Fusonic.Extensions.AspNetCore" Version="9.5.0" />
paket add Fusonic.Extensions.AspNetCore --version 9.5.0
#r "nuget: Fusonic.Extensions.AspNetCore, 9.5.0"
// Install Fusonic.Extensions.AspNetCore as a Cake Addin #addin nuget:?package=Fusonic.Extensions.AspNetCore&version=9.5.0 // Install Fusonic.Extensions.AspNetCore as a Cake Tool #tool nuget:?package=Fusonic.Extensions.AspNetCore&version=9.5.0
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 Mediator requests
Mediator 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 Mediator 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.
OpenTelemetry
Mediator tracing
To easily trace every request and notification sent by our Mediator-package, simply register the tracing decorators:
container.RegisterMediatorTracingDecorators();
container.RegisterMediator( /* Mediator configuration */ );
Also, when configuring the OpenTelemetry-Tracer, you need to enable the instrumentation:
services.AddOpenTelemetry()
.WithTracing(tracer => tracer.AddMediatorInstrumentation());
Note that the order matters. You must register the tracing decorators before mediator.
Product | Versions 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. |
-
net8.0
- Fusonic.Extensions.Common (>= 9.5.0)
- Fusonic.Extensions.Mediator (>= 9.5.0)
- OpenTelemetry.Api (>= 1.9.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Fusonic.Extensions.AspNetCore:
Package | Downloads |
---|---|
Fusonic.Extensions.Email
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.5.0 | 124 | 10/4/2024 |
9.4.0 | 223 | 9/23/2024 |
9.3.1 | 197 | 9/11/2024 |
9.3.0 | 118 | 9/11/2024 |
9.2.0 | 134 | 8/8/2024 |
9.2.0-rc.3 | 50 | 8/7/2024 |
9.2.0-rc.2 | 33 | 8/5/2024 |
9.2.0-rc.1 | 44 | 8/1/2024 |
9.1.0 | 82 | 7/29/2024 |
9.0.0 | 464 | 7/17/2024 |
9.0.0-preview.2 | 63 | 6/13/2024 |
9.0.0-preview.1 | 106 | 4/5/2024 |
8.1.3 | 237 | 3/27/2024 |
8.1.2 | 123 | 3/27/2024 |
8.1.1 | 172 | 3/1/2024 |
8.1.0 | 1,217 | 1/26/2024 |
8.0.1 | 357 | 12/18/2023 |
8.0.1-rc.2 | 86 | 12/7/2023 |
8.0.1-rc.1 | 77 | 12/6/2023 |
8.0.0 | 333 | 11/21/2023 |
8.0.0-preview1 | 153 | 10/4/2023 |
7.4.0 | 121 | 1/25/2024 |
7.3.0 | 211 | 10/11/2023 |
7.2.1-rc.1 | 95 | 8/28/2023 |
7.2.0 | 559 | 6/28/2023 |
7.2.0-alpha.1 | 90 | 6/27/2023 |
7.1.2 | 428 | 5/25/2023 |
7.1.1 | 901 | 4/3/2023 |
7.1.1-rc.2 | 88 | 3/30/2023 |
7.1.1-rc.1 | 85 | 3/30/2023 |
7.1.0 | 805 | 2/28/2023 |
7.1.0-rc.1 | 103 | 2/20/2023 |
7.0.4-rc.5 | 102 | 2/23/2023 |
7.0.4-rc.4 | 97 | 2/23/2023 |
7.0.4-rc.3 | 91 | 2/23/2023 |
7.0.4-rc.2 | 98 | 2/22/2023 |
7.0.4-rc.1 | 99 | 2/16/2023 |
7.0.3 | 411 | 2/16/2023 |
7.0.2 | 294 | 2/9/2023 |
7.0.2-rc.1 | 113 | 2/2/2023 |
7.0.1 | 733 | 1/26/2023 |
7.0.0 | 345 | 1/24/2023 |
7.0.0-preview1 | 148 | 7/18/2022 |
7.0.0-beta.9 | 112 | 1/24/2023 |
7.0.0-beta.8 | 103 | 1/23/2023 |
7.0.0-beta.7 | 103 | 1/23/2023 |
7.0.0-beta.6 | 102 | 1/23/2023 |
7.0.0-beta.5 | 113 | 1/23/2023 |
7.0.0-beta.4 | 108 | 1/19/2023 |
7.0.0-beta.3 | 102 | 1/17/2023 |
7.0.0-beta.2 | 103 | 1/11/2023 |
7.0.0-beta.1 | 89 | 11/24/2022 |
6.2.2 | 15,025 | 9/20/2022 |
6.2.2-rc.1 | 118 | 9/19/2022 |
6.2.1 | 3,156 | 5/4/2022 |
6.2.0 | 538 | 4/21/2022 |
6.2.0-rc.2 | 137 | 4/21/2022 |
6.2.0-rc.1 | 126 | 4/20/2022 |
6.1.1 | 959 | 3/1/2022 |
6.1.0 | 621 | 2/10/2022 |
6.1.0-rc.3 | 122 | 2/10/2022 |
6.1.0-rc.2 | 114 | 2/10/2022 |
6.1.0-rc.1 | 129 | 2/9/2022 |
6.0.3 | 1,492 | 1/18/2022 |
6.0.2 | 3,426 | 1/10/2022 |
6.0.1 | 295 | 12/16/2021 |
6.0.0 | 801 | 12/13/2021 |
6.0.0-rc.6 | 162 | 12/6/2021 |
6.0.0-rc.5 | 340 | 12/6/2021 |
6.0.0-rc.4 | 514 | 12/6/2021 |
6.0.0-rc.3 | 384 | 12/6/2021 |
6.0.0-rc.2 | 357 | 12/6/2021 |
6.0.0-rc.1 | 659 | 11/15/2021 |
5.4.0 | 1,007 | 10/13/2021 |
5.3.0 | 514 | 9/23/2021 |
5.3.0-rc.1 | 342 | 9/17/2021 |
5.2.0 | 3,238 | 5/20/2021 |
5.2.0-rcjh.6 | 195 | 5/19/2021 |
5.2.0-rcjh.5 | 152 | 5/19/2021 |
5.2.0-rcjh.4 | 177 | 5/19/2021 |
5.2.0-rcjh.3 | 152 | 5/19/2021 |
5.2.0-rcjh.2 | 144 | 4/12/2021 |
5.2.0-rcjh.1 | 148 | 4/12/2021 |
5.1.3 | 349 | 5/19/2021 |
5.1.2 | 14,247 | 3/26/2021 |
5.1.1 | 1,014 | 1/13/2021 |
5.1.0 | 2,040 | 12/16/2020 |
5.0.0 | 2,488 | 11/17/2020 |
5.0.0-rc.1 | 273 | 10/15/2020 |
1.1.0 | 26,311 | 8/25/2020 |
1.0.2 | 648 | 8/19/2020 |
1.0.1 | 2,778 | 7/3/2020 |
1.0.0 | 503 | 6/15/2020 |