Y.EventBus 4.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Y.EventBus --version 4.0.2                
NuGet\Install-Package Y.EventBus -Version 4.0.2                
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.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Y.EventBus --version 4.0.2                
#r "nuget: Y.EventBus, 4.0.2"                
#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.2

// Install Y.EventBus as a Cake Tool
#tool nuget:?package=Y.EventBus&version=4.0.2                

Y.EventBus

基于.NET 平台 C# 语言 提供的Channel打造的异步事件总线库

Channel使用

源码链接

使用

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);
}

image

Product 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.

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 438 9/24/2023
4.0.5 143 9/22/2023
4.0.4 139 9/22/2023
4.0.3 133 9/22/2023
4.0.2 124 9/18/2023
4.0.1 129 9/18/2023
3.0.9 159 9/17/2023
3.0.8 139 9/17/2023
3.0.7 128 9/16/2023
3.0.6 131 9/16/2023
3.0.5 159 9/16/2023
3.0.4 140 9/16/2023
3.0.3 149 9/16/2023
3.0.2 128 9/15/2023
3.0.1 150 9/15/2023
2.0.8 152 9/15/2023
2.0.7 138 9/15/2023
2.0.6 143 9/15/2023
2.0.5 147 9/15/2023
2.0.4 139 9/15/2023
2.0.3 136 9/14/2023
2.0.2 154 9/14/2023
2.0.1 151 9/14/2023
2.0.0 150 9/14/2023