Asgard.Yggdrasil.AspNetCore 4.0.2

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

Asgard.Yggdrasil.AspNetCore

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

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

适用场景

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

安装

dotnet add package Asgard.Yggdrasil.AspNetCore

推荐接入方式

推荐模型如下:

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

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

快速开始

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");
    });

var app = builder.Build();
await app.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: ""
  auth:
    enabled: false
  healthCheck:
    enabled: true
  rateLimiting:
    enabled: false

host.staticFileshost.authhost.swaggerhost.healthCheckhost.rateLimiting 是推荐优先使用的宿主配置入口。

运行时插件扫描

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

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 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 Asgard.Yggdrasil.AspNetCore:

Package Downloads
Asgard.PluginSdk

Common plugin development dependencies and convenience APIs for Asgard plugins.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.1.1 35 4/15/2026
4.1.0 39 4/14/2026
4.0.5 84 4/11/2026
4.0.4 88 4/10/2026
4.0.3 88 4/9/2026
4.0.2 92 4/8/2026
4.0.1 101 4/3/2026
4.0.0 104 4/1/2026
4.0.0-preview.7 51 3/31/2026
4.0.0-preview.6 49 3/30/2026
4.0.0-preview.5 137 3/28/2026
4.0.0-preview.4 45 3/27/2026