Asgard.Core 7.0.0

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

Asgard.Core

Asgard.Core 是 Asgard 的核心实现包,提供缓存、任务调度、消息、日志、插件、安全和配置等默认基础设施能力。

如果你已经确定要使用 Asgard 的运行时行为,而不只是依赖接口定义,这个包通常是核心依赖。

适用场景

  • 需要 Asgard 的默认基础设施实现
  • 想统一接入缓存、消息、调度、插件和安全能力
  • 需要基于 Asgard.Abstractions 的契约直接落地运行时

包含内容

  • 基于 Redis 的单层缓存能力
  • 基于 Redis 的轻量分布式锁能力
  • 基于 Quartz 的任务调度与触发器管理
  • 基于 RabbitMQ 的消息基础设施
  • 日志、安全、插件加载和 YAML 配置帮助器

Redis 消息能力

启用 caching.enabled 后,Yggdrasil 自动装配 IRedisPubSub 和 IRedisStream,它们复用缓存的 Redis 连接、caching.redis.instanceName,Stream 还使用配置的逻辑数据库。自定义宿主调用 AddAsgardCache 即可注册,业务也可通过 AbsAsgardContext.RedisPubSub 和 RedisStream 获取。缓存关闭时上下文属性为 null,直接解析消息服务会抛出异常,不会静默丢弃消息。

// Pub/Sub 是即时广播;每个订阅都应单独释放。
await using var subscription = await pubSub.SubscribeAsync("orders", cancellationToken);
await pubSub.PublishAsync("orders", "created", cancellationToken);
var message = await subscription.ReadAsync(cancellationToken);

// Stream 支持消息记录、消费组和手动确认。
await stream.CreateGroupAsync("orders", "workers", cancellationToken: cancellationToken);
await stream.AddAsync("orders", new Dictionary<string, string> { ["event"] = "created" }, cancellationToken);
var messages = await stream.ReadGroupAsync("orders", "workers", "worker-1", cancellationToken: cancellationToken);
foreach (var item in messages)
{
    // 完成业务处理后再确认;业务处理应支持重复投递。
    await stream.AcknowledgeAsync("orders", "workers", [item.Id], cancellationToken);
}

Pub/Sub 不持久化,断线或无订阅者期间的消息不会重放;Redis 频道不按逻辑数据库隔离,频道以 instanceName + pubsub: 区分应用。Stream 消息保存在 Redis 中,重启后的持久性取决于 Redis 持久化配置;键以 instanceName + stream: 区分,只支持字段名不重复的文本消息,读取不阻塞,也不自动确认或重试;可用 PendingAsync 查询待处理消息、ClaimAsync 转移超时消息。删除或修剪消息不会自动清除待确认记录。缓存的单键、批量和前缀删除会原子跳过 Redis Stream,已有缓存键及 Stream 键保持不变。缓存键与 Stream 物理键完全重合时,两者无法同时占用该键,缓存读写会因类型不匹配失败;请为两类数据使用不同名称。滚动升级期间,旧版本实例的缓存删除仍可能删除 Stream,须待所有实例升级后再依赖此保护。取消等待不保证已发送的 Redis 命令被撤销,故障恢复与幂等处理由业务负责。这些接口不自动按租户隔离,业务需要自行设计频道、流名称和访问边界。

安装

dotnet add package Asgard.Core

快速开始

using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();

services.AddAsgardContext();
services.AddAsgardSecurityServices(options =>
{
    options.Key = "base64-key";
    options.Iv = "base64-iv";
});

独立容器中启用 Redis 后可以直接注册分布式锁,所有行为参数都有默认值:

services.AddSingleton(cacheConfig);
services.AddDistributedLock();

使用 Asgard.Yggdrasil.AspNetCore 时无需手动注册;宿主会在 Redis 可用时自动装配, 并默认启用基于 owner token 校验的安全释放与自动续租。

包关系

  • Asgard.Abstractions:只提供契约和共享模型
  • Asgard.Core:提供默认运行时实现
  • Asgard.AspNetCore.Core:在 Asgard.Core 之上提供 Web 运行时集成
  • Asgard.Yggdrasil.AspNetCore:在更高层提供完整宿主体验

相关资源

如果你计划在 AI 协作场景下使用 Asgard.Core,建议把 Asgard.Skills 一起接入,这样模型能直接理解 Asgard 的项目结构、规范和推荐用法。

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

Showing the top 4 NuGet packages that depend on Asgard.Core:

Package Downloads
Asgard.AspNetCore.Core

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

Asgard.Yggdrasil.AspNetCore

Asgard.Yggdrasil.AspNetCore 是 Asgard 框架的 ASP.NET Core 主机层,集成 OpenAPI、Scalar、数据保护、日志和核心服务。

Asgard.PluginSdk

Common plugin development dependencies and convenience APIs for Asgard plugins.

Asgard.JsonConverterExtends

沐豆科技阿斯加德框架集,一切为了.NET开发的便利性

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 8 11/19/2026
7.2.0 69 11/17/2026
7.1.0 71 11/17/2026
7.0.0 123 11/13/2026
6.1.0 155 11/6/2026
6.0.4 169 10/24/2026
6.0.3 172 10/11/2026
6.0.2 150 10/8/2026
6.0.1 139 10/8/2026
6.0.0 134 10/1/2026
5.3.0 206 10/1/2026
5.2.3 136 10/1/2026
5.2.2 232 9/1/2026
5.2.1 153 8/26/2026
5.2.0 217 8/6/2026
5.1.5 171 8/4/2026
5.1.4 175 8/3/2026
5.1.3 183 7/26/2026
5.1.2 215 7/20/2026
Loading failed