Asgard.Abstractions.AspNetCore 4.1.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Asgard.Abstractions.AspNetCore --version 4.1.3
                    
NuGet\Install-Package Asgard.Abstractions.AspNetCore -Version 4.1.3
                    
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="Asgard.Abstractions.AspNetCore" Version="4.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Asgard.Abstractions.AspNetCore" Version="4.1.3" />
                    
Directory.Packages.props
<PackageReference Include="Asgard.Abstractions.AspNetCore" />
                    
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 Asgard.Abstractions.AspNetCore --version 4.1.3
                    
#r "nuget: Asgard.Abstractions.AspNetCore, 4.1.3"
                    
#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 Asgard.Abstractions.AspNetCore@4.1.3
                    
#: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=Asgard.Abstractions.AspNetCore&version=4.1.3
                    
Install as a Cake Addin
#tool nuget:?package=Asgard.Abstractions.AspNetCore&version=4.1.3
                    
Install as a Cake Tool

Asgard.Abstractions.AspNetCore

Asgard.Abstractions.AspNetCore 是 Asgard 面向 ASP.NET Core 的契约包,提供控制器基类、主机配置模型、身份上下文接口以及 AsgardAuth 声明层 API。

如果你要基于 Asgard 约定自己封装 Web 集成,但又不想直接依赖完整运行时实现,可以优先使用这个包。

适用场景

  • 构建自定义 ASP.NET Core 集成层
  • 只依赖 Web 契约,不直接引入运行时实现
  • 复用 BaseController、请求响应模型和宿主配置模型
  • 在控制器或端点上声明 AsgardAuth* 权限规则

包含内容

  • Asgard 风格控制器基类
  • host.* 配置模型,包括鉴权、CORS、Kestrel、Swagger 等
  • Web 身份上下文相关接口与模型
  • AsgardAuth* 声明型权限特性
  • Web 集成会复用的请求响应模型

安装

dotnet add package Asgard.Abstractions.AspNetCore

快速开始

using Asgard.Abstractions.AspNetCore.Controller;
using Asgard.Abstractions.AspNetCore.Model;

public sealed class HealthController : BaseController
{
    [HttpGet("health")]
    public ActionResult<Response<string>> Get()
        => Ok(Response.Success("ok"));
}

AsgardAuth 声明方式

AsgardAuth 特性是 Asgard 权限模型的声明层,可以和 ASP.NET Core 原生 [Authorize] 一起使用。

[Authorize]
[AsgardAuthAnyRole("admin", "ops")]
[AsgardAuthUserMetadataEquals("department", "engineering")]
public ActionResult<string> Get()
    => Ok("ok");

需要线性布尔组合时,可以使用 AsgardAuthAndAsgardAuthOr

[AsgardAuthAnyRole("admin")]
[AsgardAuthOr]
[AsgardAuthUserMetadataEquals("department", "platform")]
public ActionResult<string> Get()
    => Ok("ok");

复杂条件可以使用内置 DSL:

[AsgardAuthMatch("name like 'ben' and metadata.level >= '3' and contains(name, 'en')")]
public ActionResult<string> Get()
    => Ok("ok");

如果需要区分 JWT 中的令牌类型,也可以直接使用 token_type 字段:

[AsgardAuthMatch("token_type = 'BackendService'")]
public ActionResult<string> Run()
    => Ok("ok");

推荐搭配

  • 只要契约:Asgard.Abstractions.AspNetCore
  • 要运行时能力:Asgard.AspNetCore.Core
  • 要完整主机启动:Asgard.Yggdrasil.AspNetCore

相关资源

如果你会结合 AI 工具一起开发 Asgard Web 项目,建议直接配套使用 Asgard.Skills 仓库中的技能定义和开发规范。

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 (2)

Showing the top 2 NuGet packages that depend on Asgard.Abstractions.AspNetCore:

Package Downloads
Asgard.AspNetCore.Core

Asgard.AspNetCore.Core 为 Asgard 框架提供 ASP.NET Core 运行时实现,包括租户感知中间件、身份上下文集成和服务注册帮助器,构建在共享抽象包之上。

Asgard.TsGen

Asgard.TsGen generates reusable TypeScript clients by scanning ASP.NET Core controllers decorated with AsgardTsGenAttribute.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.1.7 132 5/24/2026
4.1.6 134 5/24/2026
4.1.5 132 5/23/2026
4.1.4 139 5/16/2026
4.1.3 144 4/28/2026
4.1.2 127 4/21/2026
4.1.1 136 4/15/2026
4.1.0 141 4/14/2026
4.0.5 131 4/11/2026
4.0.4 145 4/10/2026
4.0.3 120 4/9/2026
4.0.2 124 4/8/2026
4.0.1 134 4/3/2026
4.0.0 138 4/1/2026
4.0.0-preview.7 70 3/31/2026
4.0.0-preview.6 70 3/30/2026
4.0.0-preview.5 156 3/28/2026
4.0.0-preview.4 65 3/27/2026
4.0.0-preview.3 65 3/27/2026
Loading failed