NotMediator 1.0.5
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package NotMediator --version 1.0.5
NuGet\Install-Package NotMediator -Version 1.0.5
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="NotMediator" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NotMediator" Version="1.0.5" />
<PackageReference Include="NotMediator" />
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 NotMediator --version 1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NotMediator, 1.0.5"
#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 NotMediator@1.0.5
#: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=NotMediator&version=1.0.5
#tool nuget:?package=NotMediator&version=1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
一个通过反射实现了简易MediatoR的中介者消息传递类库
这里是使用示例
///要发布的请求类
public class TestParent:IRequest<string>{
public string Name { get; set; }
public TestParent(string name)
{
Name = name;
}
}
///实现请求的具体实现
public class TestParendHandler:IRequestHandler<TestParent,string>
{
public Task<string> Handler(TestParent request, CancellationToken cancellationToken){
return Task.FromResult($"{request.Name}");
}
}
///管道依赖于请求的实现
public class LoggerPipeline:IPipelineBehavior<TestParent,string>{
public Task<TResponse> Handle(TRequest request,Func<Task<TRequest>> next ,CancellationToken cancellationToken)
{
Console.WriteLine($"{nameof(LoggerPipeline)}");
var result = await next();
Console.WriteLine($"{result}");
return result;
}
}
这里是通知使用示例
public class TestNotify:INotification{
public string Name { get; set; }
public TestNotify(string name){
Name = name;
}
}
public class TestNotifyHandler:INotificationHandler<TestNotify>{
public Task Handle(TestNotify notification, CancellationToken cancellationToken){
Console.WriteLine($"{notification.Name}");
return Task.CompletedTask;
}
}
对上面的使用示例进行注册
///在Asp.net core中program.cs中添加
builder.Services.AddMediator(Assembly.GetExecutingAssembly());
//注册管道
builder.Services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggerPipeline<,>));
如需在控制台应用中使用,请使用以下代码 需要引入 Microsoft.Extensions.DependencyInjection,NotMediator
var services=new ServiceCollection();
services.AddMediator(Assembly.GetExecutingAssembly());
var serviceProvider = services.BuildServiceProvider();
//管道需要手动注册
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggerPipeline<,>));
//获取中介者
var mediator = services.GetService<IMediator>();
//发送通知
await mediator.Publish(new TestNotify("hello"));
//发送请求
await mediator.Send(new TestParent("hello"));
Console.ReadLine();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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.
-
net9.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.