Y.EventBus
4.0.6
dotnet add package Y.EventBus --version 4.0.6
NuGet\Install-Package Y.EventBus -Version 4.0.6
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.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Y.EventBus --version 4.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Y.EventBus, 4.0.6"
#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.6 // Install Y.EventBus as a Cake Tool #tool nuget:?package=Y.EventBus&version=4.0.6
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 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 | 432 | 9/24/2023 |
4.0.5 | 139 | 9/22/2023 |
4.0.4 | 135 | 9/22/2023 |
4.0.3 | 129 | 9/22/2023 |
4.0.2 | 120 | 9/18/2023 |
4.0.1 | 125 | 9/18/2023 |
3.0.9 | 153 | 9/17/2023 |
3.0.8 | 135 | 9/17/2023 |
3.0.7 | 124 | 9/16/2023 |
3.0.6 | 127 | 9/16/2023 |
3.0.5 | 155 | 9/16/2023 |
3.0.4 | 136 | 9/16/2023 |
3.0.3 | 145 | 9/16/2023 |
3.0.2 | 124 | 9/15/2023 |
3.0.1 | 146 | 9/15/2023 |
2.0.8 | 148 | 9/15/2023 |
2.0.7 | 134 | 9/15/2023 |
2.0.6 | 137 | 9/15/2023 |
2.0.5 | 143 | 9/15/2023 |
2.0.4 | 135 | 9/15/2023 |
2.0.3 | 132 | 9/14/2023 |
2.0.2 | 150 | 9/14/2023 |
2.0.1 | 147 | 9/14/2023 |
2.0.0 | 146 | 9/14/2023 |