Y.EventBus
3.0.7
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 3.0.7
NuGet\Install-Package Y.EventBus -Version 3.0.7
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="3.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Y.EventBus --version 3.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Y.EventBus, 3.0.7"
#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=3.0.7 // Install Y.EventBus as a Cake Tool #tool nuget:?package=Y.EventBus&version=3.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Y.EventBus
基于.NET 平台 C# 语言 提供的Channle打造的异步事件总线库
Channle使用
源码链接
使用
EventDiscriptorAttribute 特性
[AttributeUsage(AttributeTargets.Class,AllowMultiple = false,Inherited = false)]
public class EventDiscriptorAttribute:Attribute
{
/// <summary>
/// 事件2名称
/// </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.AddChannles(p =>
{
p.TryAddChannle<TestEto>();
});
注入EventBus
context.Services.AddEventBus();
创建订阅Eto
var scope = context.ServiceProvider.CreateScope();
var eventhandlerManager = scope.ServiceProvider.GetRequiredService<IEventHandlerManager>();
await authorizeManager.AddAuthorizeRegiester();
await eventhandlerManager.CreateChannles();
eventhandlerManager.Subscribe<TestEto>();
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
- Newtonsoft.Json (>= 13.0.3)
- Y.Module (>= 2.0.0)
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 |