Zzdats.Lgp.Common.Web 10.0.10

Prefix Reserved
dotnet add package Zzdats.Lgp.Common.Web --version 10.0.10
                    
NuGet\Install-Package Zzdats.Lgp.Common.Web -Version 10.0.10
                    
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="Zzdats.Lgp.Common.Web" Version="10.0.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zzdats.Lgp.Common.Web" Version="10.0.10" />
                    
Directory.Packages.props
<PackageReference Include="Zzdats.Lgp.Common.Web" />
                    
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 Zzdats.Lgp.Common.Web --version 10.0.10
                    
#r "nuget: Zzdats.Lgp.Common.Web, 10.0.10"
                    
#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 Zzdats.Lgp.Common.Web@10.0.10
                    
#: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=Zzdats.Lgp.Common.Web&version=10.0.10
                    
Install as a Cake Addin
#tool nuget:?package=Zzdats.Lgp.Common.Web&version=10.0.10
                    
Install as a Cake Tool

Common-Web

Zzdats.Lgp.Common.Web satur kopējo infrastruktūru web projektiem (API, MVC): logošanu, health check, Prometheus metrikas, APM un autentifikācijas apstrādātājus.

Bibliotēka ir daļa no LGP kopīgo komponenšu kopas (Zzdats.Lgp.*).

Prasības

  • .NET 10

Uzstādīšana

dotnet add package Zzdats.Lgp.Common.Web

Izmantošana

Program.cs:

var builder = WebApplication.CreateBuilder(args);

builder.Host.UseLgpCore();
builder.WebHost.UseLgpCore();
builder.Services.AddLgpCore(builder.Configuration.GetSection("Lgp"));

var app = builder.Build();

app.UseLgpCore();

app.Run();

Projektos, kas vēl izmanto Startup klasi, izsaukumi ir tie paši — ConfigureServices pievieno services.AddLgpCore(Configuration.GetSection("Lgp")), Configure pievieno app.UseLgpCore(), un host builder ķēdē pievieno .UseLgpCore() gan IHostBuilder, gan IWebHostBuilder līmenī:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .UseLgpCore()
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder
                .UseLgpCore()
                .UseStartup<Startup>();
        });

Iespējas, kas tiek pievienotas pēc noklusējuma

  • Health check (/healthz, atbild tikai par procesu — ārējās atkarības netiek pārbaudītas)
  • Prometheus metriku eksporta URL /metrics
  • Elastic APM (HttpDiagnosticsSubscriber un AspNetCoreDiagnosticSubscriber)
  • Log ierakstu veidošana ECS formātā

Konfigurācija

{
    "Lgp": {
        "Log": {
            "File": "./logs/log.log",
            "Console": true,
            "ConsoleTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
            "ExcludePaths": "/healthz,/metrics"
        },
        "Infrastructure": {
            "Health": {
                "Enabled": true
            },
            "Metrics": {
                "Enabled": true,
                "Authorization": "Bearer <token>"
            }
        }
    }
}

Papildus Elastic APM mērījumu pievienošana

services.AddLgpCore(Configuration.GetSection("Lgp"), opt =>
{
    opt.ElasticApmDiagnosticsSubscribers.Add(new ElasticsearchDiagnosticsSubscriber());
});

Health check

/healthz atbild uz vienu jautājumu: vai process spēj apkalpot HTTP. Tas atgriež {"status":"pass"} ar HTTP 200 un neveic nevienu datu bāzes, autentifikācijas servisa vai cita tīkla resursa izsaukumu.

Nepievienojiet šim galapunktam ārējo atkarību pārbaudes. Konteinera veselības pārbaude var tikai pārstartēt procesu, un nesasniedzamu atkarību restarts nesalabo — tā vietā tas pārvērš atkarības pārtraukumu restartu ciklā. Ja atkarība neatbild, kļūdu saņem tie pieprasījumi, kuriem tā bija vajadzīga; pieejamību mēra monitorings.

Prometheus eksporteris

Lai ieslēgtu metriku eksportēšanu uz /metrics, Lgp:Infrastructure:Metrics:Enabled jābūt true.

Lai aizsargātu šo galapunktu, Lgp:Infrastructure:Metrics:Authorization jānorāda, kāds Authorization header tiks padots pieprasījumā no Prometheus — pretējā gadījumā /metrics atbild ar 401 Unauthorized. Tas pats header jānorāda arī Prometheus metriku ievācējam (scraper).

Autorizēta izsaukuma piemērs:

GET /metrics HTTP/1.1
Host: localhost:5000
Authorization: Bearer <token>

Atbilde satur ASP.NET Core pieprasījumu metrikas un .NET izpildlaika skaitītājus, piemēram:

# HELP http_requests_received_total Provides the count of HTTP requests that have been processed by the ASP.NET Core pipeline.
# TYPE http_requests_received_total counter
http_requests_received_total{code="200",method="GET",controller="Example",action="Get",endpoint="api/example"} 1

# HELP http_request_duration_seconds The duration of HTTP requests processed by an ASP.NET Core application.
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_sum{code="200",method="GET",controller="Example",action="Get",endpoint="api/example"} 0.0123
http_request_duration_seconds_count{code="200",method="GET",controller="Example",action="Get",endpoint="api/example"} 1

# HELP dotnet_gc_heap_size_bytes The current size of all heaps (only updated after a garbage collection)
# TYPE dotnet_gc_heap_size_bytes gauge
dotnet_gc_heap_size_bytes{gc_generation="0"} 8388600

Pilns skaitītāju saraksts ir prometheus-net un prometheus-net.DotNetRuntime dokumentācijā.

IDAuth adaptera autentifikācija

Bibliotēka satur IDAuth autentifikācijas apstrādātāju. Apstrādātājs noraida talonu, ja IDAuth sesija nav aktīva (active: false), un izlaiž cauri JWT talonus (talonus, kas satur punktu), lai tos apstrādātu JWT shēma.

Apstrādātāja adresi padod options.AuthUrl — bibliotēka pati nenolasa nevienu konfigurācijas atslēgu, tāpēc ceļš Lgp:Infrastructure:IdAuth:Url (vides mainīgais LGP__INFRASTRUCTURE__IDAUTH__URL) ir tikai ieteicamā vienošanās:

services.AddAuthentication(opt =>
{
    opt.DefaultScheme = IDAuthDefaults.AuthenticationScheme;
})
.AddScheme<IDAuthAuthenticationOptions, IDAuthAuthenticationHandler>(IDAuthDefaults.AuthenticationScheme, options =>
{
    options.AuthUrl = Configuration.GetValue<string>("Lgp:Infrastructure:IdAuth:Url");
});

Var reģistrēt arī vairākus apstrādātājus, lai neapstrādātu IDAuth talonu gadījumā notiktu atkāpšanās (fallback) uz JWT taloniem:

services.AddAuthentication(opt =>
{
    opt.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(opt =>
{
    opt.Authority = Configuration.GetValue<string>("Lgp:Infrastructure:Authority:Url");
    opt.RequireHttpsMetadata = !Environment.IsDevelopment();
    opt.TokenValidationParameters = new TokenValidationParameters()
    {
        ValidateAudience = false,
    };
})
.AddScheme<IDAuthAuthenticationOptions, IDAuthAuthenticationHandler>(IDAuthDefaults.AuthenticationScheme, options =>
{
    options.AuthUrl = Configuration.GetValue<string>("Lgp:Infrastructure:IdAuth:Url");
});

Kontroliera klasē tad norāda abas shēmas:

[ApiController]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + IDAuthDefaults.AuthenticationScheme)]
public class ExampleController : ApiControllerBase

Būvēšana

dotnet build
dotnet test
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 (1)

Showing the top 1 NuGet packages that depend on Zzdats.Lgp.Common.Web:

Package Downloads
Zzdats.Lgp.Common.Mvc

MVC LGP common components and infrastructure integration

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.10 256 10/6/2026
10.0.9 184 9/14/2026
10.0.8 124 9/14/2026
10.0.7 339 8/25/2026
8.0.17 539 9/14/2026
8.0.16 108 9/14/2026
8.0.15 122 9/14/2026
8.0.14 133 8/25/2026