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.
<PackageVersion Include="Y.EventBus" Version="4.0.6" />
<PackageReference Include="Y.EventBus" />
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 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.
#:package Y.EventBus@4.0.6
#: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=Y.EventBus&version=4.0.6
#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. net9.0 was computed. 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.
-
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 | 575 | 9/24/2023 |
| 4.0.5 | 225 | 9/22/2023 |
| 4.0.4 | 234 | 9/22/2023 |
| 4.0.3 | 215 | 9/22/2023 |
| 4.0.2 | 224 | 9/18/2023 |
| 4.0.1 | 231 | 9/18/2023 |
| 3.0.9 | 237 | 9/17/2023 |
| 3.0.8 | 232 | 9/17/2023 |
| 3.0.7 | 207 | 9/16/2023 |
| 3.0.6 | 212 | 9/16/2023 |
| 3.0.5 | 241 | 9/16/2023 |
| 3.0.4 | 226 | 9/16/2023 |
| 3.0.3 | 246 | 9/16/2023 |
| 3.0.2 | 216 | 9/15/2023 |
| 3.0.1 | 230 | 9/15/2023 |
| 2.0.8 | 233 | 9/15/2023 |
| 2.0.7 | 228 | 9/15/2023 |
| 2.0.6 | 226 | 9/15/2023 |
| 2.0.5 | 242 | 9/15/2023 |
| 2.0.4 | 224 | 9/15/2023 |
Loading failed