Asgard.Yggdrasil.AspNetCore 8.1.0

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

Asgard.Yggdrasil.AspNetCore

Asgard.Yggdrasil.AspNetCore 是 Asgard 的 ASP.NET Core 宿主包,面向希望保留自己应用入口、同时复用 Asgard 基础设施和插件生命周期的团队。

对于大多数应用团队来说,这通常是最推荐的 NuGet 入口。

适用场景

  • 自己维护 Program.cs,但想快速获得 Asgard 主机能力
  • 使用内建插件模式组织业务模块
  • 统一接入 OpenAPI、鉴权、健康检查、静态资源和插件生命周期
  • 需要完整宿主体验,而不是只要单个运行时能力

安装

dotnet add package Asgard.Yggdrasil.AspNetCore

推荐接入方式

推荐模型如下:

  1. 创建你自己的 ASP.NET Core 应用。
  2. 引用 Asgard.Yggdrasil.AspNetCore。
  3. 通过 YggdrasilHost 启动宿主。
  4. 把业务模块组织成一个或多个内建插件。

这种方式既保留了应用自身对入口和中间件的控制权,也能让 Asgard 统一管理服务注册、插件生命周期和宿主能力。

单插件 Starter

引用本包后可直接启动内建插件。插件项目需要服务扫描、配置绑定或对象映射时引用 Asgard.PluginSdk。

using Asgard.PluginSdk;

await PluginWebAppDefaults.RunAsync<MyPlugin>("config/app.yaml");

快速开始

Program.cs

using Asgard.Yggdrasil.AspNetCore;
using Asgard.Abstractions.AspNetCore.Extensions;
using Microsoft.AspNetCore.Builder;

var builder = YggdrasilHost.CreateBuilder("config/app.yaml")
    .UseBuiltInPlugin<MyBusinessPlugin>()
    .ConfigureMiddleware(app =>
    {
        app.UseAsgardExceptionHandler()
           .UseHttpsRedirection();
    })
    .AfterHostBuild(_ =>
    {
        Console.WriteLine("[OK] Asgard Yggdrasil host started");
    });

await builder.RunAsync();

如果项目里看不到 YggdrasilHost,请优先确认:

  1. 项目已经引用 Asgard.Yggdrasil.AspNetCore
  2. Program.cs 中包含 using Asgard.Yggdrasil.AspNetCore;

内建插件

using Asgard.Core.Plugin;
using Asgard.Abstractions.Plugin;

public sealed class MyBusinessPlugin : PluginBase
{
    public override string Id => "member-center";

    public override string Name => "Member Center";

    public override Version Version => new(1, 0, 0);

    protected override Task OnConfigureServicesAsync(
        IPluginServiceConfigurationContext context,
        CancellationToken cancellationToken)
    {
        context.Services.AddScoped<IMemberService, MemberService>();
        return Task.CompletedTask;
    }

    protected override Task OnConfigureMiddlewareAsync(
        IPluginMiddlewareConfigurationContext context,
        CancellationToken cancellationToken)
    {
        context.App.MapControllers();
        return Task.CompletedTask;
    }
}

配置说明

当前宿主默认读取类似 config/app.yaml 的配置文件,并优先使用 host.* 节点管理宿主级能力。

最小示例:

host:
  application:
    name: "MyApp"
    version: "1.0.0"
    environment: "Development"
  staticFiles:
    enabled: true
    webRootPath: "wwwroot"
    requestPath: ""
    enableDefaultFiles: true
    defaultFiles:
      - "index.html"
  auth:
    enabled: false
  healthCheck:
    enabled: true
    timeoutSeconds: 30
    requiredFeatures: []
  rateLimiting:
    enabled: false
    policy: "FixedWindow"
    permitLimit: 100
    windowSeconds: 60
    queueLimit: 0
    ip:
      enabled: false
    user:
      enabled: false

host.staticFiles、host.auth、host.openApi、host.healthCheck 和 host.rateLimiting 是推荐优先使用的宿主配置入口。

将接流量所需的依赖写入 host.healthCheck.requiredFeatures,支持 Redis、MessageQueue、JobScheduler 和 Database。相应探测失败会使 /health/ready 返回 HTTP 503,/health/live 检查进程存活。通过 asgardContext.Config.Configuration 可查看生效的模块开关和探测配置。见 Context 能力清单。

host.rateLimiting 的现有扁平算法字段继续表示当前实例共享的总量桶;可选的 ip 层在认证前按远端地址分区,可选的 user 层在身份建立后按租户与主体分区。未配置两个子节点时,旧版限流行为保持不变。

运行时插件扫描

目录扫描式插件发现仍然可用,但更适合作为可选扩展机制,而不是普通应用的默认接入方式:

plugin:
  enabled: true
  scanDirectories:
    - path: "plugins"
      enabled: true
      recursive: false
      entryPointPattern: "*.Plugin.dll"

这更适用于部署期扩展、热插拔场景和私有插件市场。

相关包

  • Asgard.AspNetCore.Core
  • Asgard.Core
  • Asgard.Abstractions
  • Asgard.Abstractions.AspNetCore
  • Asgard.PluginSdk

相关资源

Asgard.Skills 是 Asgard 官方 AI 技能仓库,包含宿主项目、插件开发、API 开发等配套技能定义。若你会使用 AI 助手参与项目搭建,建议直接配套使用。

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
8.1.0 0 11/19/2026
8.0.0 9 11/19/2026
7.2.0 60 11/17/2026
7.1.0 66 11/17/2026
7.0.0 105 11/13/2026
6.1.0 124 11/6/2026
6.0.4 141 10/24/2026
6.0.3 155 10/11/2026
6.0.2 126 10/8/2026
6.0.1 106 10/8/2026
6.0.0 118 10/1/2026
5.3.0 191 10/1/2026
5.2.3 109 10/1/2026
5.2.2 145 9/1/2026
5.2.1 125 8/26/2026
5.2.0 194 8/6/2026
5.1.5 140 8/4/2026
5.1.4 146 8/3/2026
5.1.3 148 7/26/2026
5.1.2 180 7/20/2026
Loading failed