SH.Mediator
1.1.9
dotnet add package SH.Mediator --version 1.1.9
NuGet\Install-Package SH.Mediator -Version 1.1.9
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="SH.Mediator" Version="1.1.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SH.Mediator" Version="1.1.9" />
<PackageReference Include="SH.Mediator" />
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 SH.Mediator --version 1.1.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SH.Mediator, 1.1.9"
#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 SH.Mediator@1.1.9
#: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=SH.Mediator&version=1.1.9
#tool nuget:?package=SH.Mediator&version=1.1.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
<center> 使用方式
请您等他升级到 2.0 版本后再使用
安装 NuGet 包
dotnet add package SHMediator
注册服务
using SHMediator;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddSHMediator(typeof(Program).Assembly);
三种 接口
1. IRequest -- IRequestHandler
2. IRequest<,> -- IRequestHandler<,>
3. INotification -- INotificationHandler
1. IRequest -- IRequestHandler
public class MyRequest : IRequest<MyResponse>
{
public string Name { get; set; }
}
public class MyResponse
{
public string Message { get; set; }
}
public class MyRequestHandler : IRequestHandler<MyRequest, MyResponse>
{
public Task<MyResponse> Handle(MyRequest request, CancellationToken cancellationToken)
{
return Task.FromResult(new MyResponse { Message = $"Hello, {request.Name}!" });
}
}
// 使用
var mediator = serviceProvider.GetRequiredService<IMediator>();
var response = await mediator.Send(new MyRequest { Name = "World" });
Console.WriteLine(response.Message); // 输出: Hello, World!
2. INotification -- INotificationHandler
public class MyNotify : INotification
{
public string Name { get; set; }
}
public class MyNotify1Handlder : INotificationHandler<MyNotify>
{
Task Handle(TNotification notification)
{
Console.WriteLine("")
}
}
public class MyNotify2Handlder : INotificationHandler<MyNotify>
{
Task Handle(TNotification notification)
{
Console.WriteLine("")
}
}
更新内容
- 添加自动注册验证Validator功能
- 更新添加拦截器 并支持自定义
文档目录
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- FluentValidation.DependencyInjectionExtensions (>= 12.1.1)
- Microsoft.Extensions.DependencyInjection (>= 10.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.