Y.EventBus
4.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 Y.EventBus --version 4.0.5
NuGet\Install-Package Y.EventBus -Version 4.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="Y.EventBus" Version="4.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Y.EventBus --version 4.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Y.EventBus, 4.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.
// Install Y.EventBus as a Cake Addin #addin nuget:?package=Y.EventBus&version=4.0.5 // Install Y.EventBus as a Cake Tool #tool nuget:?package=Y.EventBus&version=4.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Y.EventBus
基于.NET 平台 C# 语言 提供的Channel打造的异步事件总线库
Channel使用
源码链接
使用
EventDiscriptorAttribute 特性
[AttributeUsage(AttributeTargets.Class,AllowMultiple = false,Inherited = false)]
public class EventDiscriptorAttribute:Attribute
{
/// <summary>
/// 事件名称
/// </summary>
public string EventName { get; private set; }
/// <summary>
/// channel 容量设置
/// </summary>
public int Capacity { get; private set; }
/// <summary>
/// 是否维持一个生产者多个消费者模型
/// </summary>
public bool SigleReader { get; private set; }
public EventDiscriptorAttribute(string eventName, int capacity = 1000, bool sigleReader = true)
{
EventName = eventName;
Capacity = capacity;
SigleReader = sigleReader;
}
}
Eto 实现特性
[EventDiscriptor("test",1000,false)]
public class TestEto
{
public string Name { get; set; }
public string Description { get; set; }
}
添加通信管道
context.Services.Subscribes(p =>
{
p.Subscribe<TestEto,TestEventHandler>();
});
注入EventBus
context.Services.AddEventBus();
创建订阅Eto
var scope = context.ServiceProvider.CreateScope();
var eventhandlerManager = scope.ServiceProvider.GetRequiredService<IEventHandlerManager>();
await authorizeManager.AddAuthorizeRegiester();
await eventhandlerManager.CreateChannles();
EventHandler定义
public class TestEventHandler : IEventHandler<TestEto>,ITransientInjection
{
private ILogger _logger;
public TestEventHandler(ILoggerFactory factory)
{
_logger = factory.CreateLogger<TestEventHandler>();
}
public Task HandelrAsync(TestEto eto)
{
_logger.LogInformation($"{typeof(TestEto).Name}--{eto.Name}--{eto.Description}");
return Task.CompletedTask;
}
}
//注意EventHandler的生命周期请使用AddTrasint() 或者AddScoped()
//构造函数注入即可使用
TestEto eto = null;
for(var i = 0; i < 100; i++)
{
eto = new TestEto()
{
Name ="LocalEventBus" + i.ToString(),
Description ="wyg"+i.ToString(),
};
await _localEventBus.PublichAsync(eto,CancellationToken.None);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Hosting (>= 7.0.1)
- Newtonsoft.Json (>= 13.0.3)
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 |
---|---|---|
4.0.6 | 436 | 9/24/2023 |
4.0.5 | 141 | 9/22/2023 |
4.0.4 | 137 | 9/22/2023 |
4.0.3 | 131 | 9/22/2023 |
4.0.2 | 122 | 9/18/2023 |
4.0.1 | 127 | 9/18/2023 |
3.0.9 | 157 | 9/17/2023 |
3.0.8 | 137 | 9/17/2023 |
3.0.7 | 126 | 9/16/2023 |
3.0.6 | 129 | 9/16/2023 |
3.0.5 | 157 | 9/16/2023 |
3.0.4 | 138 | 9/16/2023 |
3.0.3 | 147 | 9/16/2023 |
3.0.2 | 126 | 9/15/2023 |
3.0.1 | 148 | 9/15/2023 |
2.0.8 | 150 | 9/15/2023 |
2.0.7 | 136 | 9/15/2023 |
2.0.6 | 141 | 9/15/2023 |
2.0.5 | 145 | 9/15/2023 |
2.0.4 | 137 | 9/15/2023 |
2.0.3 | 134 | 9/14/2023 |
2.0.2 | 152 | 9/14/2023 |
2.0.1 | 149 | 9/14/2023 |
2.0.0 | 148 | 9/14/2023 |