Zymergi.AspNetCore
11.4.0-alpha
dotnet add package Zymergi.AspNetCore --version 11.4.0-alpha
NuGet\Install-Package Zymergi.AspNetCore -Version 11.4.0-alpha
<PackageReference Include="Zymergi.AspNetCore" Version="11.4.0-alpha" />
<PackageVersion Include="Zymergi.AspNetCore" Version="11.4.0-alpha" />
<PackageReference Include="Zymergi.AspNetCore" />
paket add Zymergi.AspNetCore --version 11.4.0-alpha
#r "nuget: Zymergi.AspNetCore, 11.4.0-alpha"
#:package Zymergi.AspNetCore@11.4.0-alpha
#addin nuget:?package=Zymergi.AspNetCore&version=11.4.0-alpha&prerelease
#tool nuget:?package=Zymergi.AspNetCore&version=11.4.0-alpha&prerelease
Zymergi.AspNetCore
Shared ASP.NET Core pieces for Zymergi apps: XSLT-rendered MVC controllers (ControllerXslt), a usage-tracking action filter (TrackUsageAttribute), and small request helpers (claims, correlation id, route data, header copy, log search model).
Targets .NET 10. Depends on Zymergi.Core, Zymergi.Data, and Zymergi.Rendering. Article and social controllers are not in this package.
Install
dotnet add package Zymergi.AspNetCore
Register in Program.cs
using Zymergi.AspNetCore;
using Zymergi.AspNetCore.Diagnostics;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddHttpContextAccessor();
builder.Services.AddXslTransformViewPool(builder.Configuration); // singleton pool; reads PATH_XSL
builder.Services.AddTrackUsage(o => o.RedactRouteData = true); // options for TrackUsageAttribute
builder.Services.AddProblemDetails();
var app = builder.Build();
app.UseExceptionHandler();
app.UseStatusCodePages();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
PATH_XSL is a folder relative to the current directory. A missing key throws when the pool is first resolved.
Use it
XSLT page controller. The pool key is the stylesheet file name without .xsl:
using Microsoft.AspNetCore.Mvc;
using Zymergi.AspNetCore.Diagnostics;
using Zymergi.AspNetCore.Mvc.Controllers;
using Zymergi.Rendering.XslTransformView;
public sealed class PagesController(IHttpContextAccessor ctx, IConfiguration config, IXslTransformViewPool xsl, PageService pages)
: ControllerXslt(ctx, config, xsl)
{
[HttpGet("/pages/{slug}")]
[TrackUsage("view page", "PagesController.Show")]
public async Task<IActionResult> Show(string slug, CancellationToken ct)
{
string? xml = await pages.GetXmlAsync(slug, ct);
if (xml is null) return NotFound();
return Content(xsl["page"].Transform(xml, _xsltArgs), "text/html");
}
}
Reading claims in a minimal API:
using System.Security.Claims;
using Zymergi.AspNetCore;
using Zymergi.AspNetCore.Logging;
app.MapGet("/me", (ClaimsPrincipal user, HttpContext http) => new
{
Email = user.Claims.GetValue("email"),
CorrelationId = http.GetCorrelationId(),
}).RequireAuthorization();
Best practices
- Authenticate with the standard handlers (
AddAuthentication().AddJwtBearer(...)or cookies plus OpenID Connect) and protect endpoints withRequireAuthorizationor[Authorize]. Read claims fromHttpContext.User, which the handler has validated. Do not parse a JWT yourself. - Errors:
AddProblemDetailsplusUseExceptionHandler, with anIExceptionHandlerfor domain errors. Do not return stack traces. - Inject services with the right lifetime: options and stateless helpers as singletons, data access through a singleton
IDbConnectionFactory(seeZymergi.Data), per-request state as scoped. Never inject a scoped service into a singleton. - Bind settings with
IOptions<T>andValidateOnStart. - Log with
ILogger<T>and message templates.TrackUsageAttributelogs one information entry per action throughILogger<TrackUsageFilter>; setRedactRouteDatawhen route values can hold personal data. - Pass
CancellationToken(orHttpContext.RequestAborted) to every async call. - Use output caching (
AddOutputCache,[OutputCache]) for public XSLT pages andHybridCachefor expensive data; use rate limiting (AddRateLimiter) on public endpoints. DefaultXsltArgsProviderpasses onlyid_name,id_picture, andid_emailaddressclaims to stylesheets, and HTML-encodes the Referer. ImplementIXsltArgsProviderto pass more. Never usedisable-output-escapingon request values.
Testing
- Use
WebApplicationFactory<Program>(Microsoft.AspNetCore.Mvc.Testing) for endpoint tests, and replace data and search services with fakes inConfigureTestServices. - Test a controller action directly by constructing it with fakes (
IXslTransformViewPool,IHttpContextAccessor). - Point
PATH_XSLat a test folder of stylesheets.
Gotchas
Zymergi.AspNetCoreandZymergi.Renderingboth defineAddXslTransformViewPool(IServiceCollection, IConfiguration). With both namespaces imported in one file, the call is ambiguous (CS0121). Import only one, or callZymergi.Rendering.ServiceCollectionExtensions.AddXslTransformViewPool(builder.Services, builder.Configuration).GetCorrelationIdis in namespaceZymergi.AspNetCore.Logging, which also holds the obsoleteTrackUsageAttribute. Importing bothZymergi.AspNetCore.LoggingandZymergi.AspNetCore.Diagnosticsin one file makes[TrackUsage]ambiguous (CS0104). CallZymergi.AspNetCore.Logging.ExtensionMethods.GetCorrelationId(http)instead of importing the namespace.- An unknown stylesheet key returns an empty view, not an exception.
- Obsolete, removed in 12.0:
DbRegistrableControllerBase<T>,CachedHttpClient,CachedServiceBase,ClaimsList(no signature check),TrackPerformanceFilter,Zymergi.AspNetCore.Logging.TrackUsageAttribute,WebLoggor,WebExtensionMethods,RefreshablePersistedAuthProperties, andRepeatController. Replacements: your own controllers,IHttpClientFactoryplusHybridCache, the JWT bearer handler,ILogger<T>, andZymergi.AspNetCore.Diagnostics.TrackUsageAttribute. HttpClient.CopyHeaderschanges the client's default headers. Use theHttpRequestMessage.CopyHeadersoverload for per-request headers.
Version notes
11.4.0-alpha: no API change. The README no longer shows ClaimsList.
11.3.0-alpha
DefaultXsltArgsProviderpasses fewer claims, encodes the Referer, and setsdtNowto local time.- The obsolete
DbRegistrableControllerBase<T>.RemoveandWebLoggor.PersistLogEntryToRepoAsyncthrowInvalidOperationException.
| Product | Versions 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. |
-
net10.0
- System.IdentityModel.Tokens.Jwt (>= 8.23.0)
- Zymergi.Core (>= 11.4.0-alpha)
- Zymergi.Data (>= 11.4.0-alpha)
- Zymergi.Rendering (>= 11.4.0-alpha)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.4.0-alpha | 95 | 11/16/2026 |
| 11.3.0-alpha | 68 | 11/12/2026 |
| 11.2.0-alpha | 62 | 11/2/2026 |
| 11.1.1-alpha | 99 | 10/4/2026 |
| 11.1.0-alpha | 108 | 10/1/2026 |
| 11.0.6-alpha | 122 | 7/10/2026 |
| 11.0.5-alpha | 129 | 7/9/2026 |
| 11.0.4-alpha | 91 | 7/6/2026 |
| 11.0.3-alpha | 81 | 7/6/2026 |
| 11.0.2-alpha | 129 | 6/30/2026 |
| 11.0.1-alpha | 123 | 6/30/2026 |
| 11.0.0-alpha | 83 | 6/30/2026 |