# 事件总线 在这里主要用来发布项目事件用的,更好的解耦代码。目前只有内存事件的实现。 ### IntegrationEvent 事件父类,所有自定以事件必须要继承这个父类。 ```csharp //操作日志记录事件 public class LogOperationEvent : IntegrationEvent { } ``` ### IEventLog 标记事件需要记录执行日志,错误日志所有事件都会记录 ### IntegrationEventHandler 事件处理器 继承这个类之后实现Run 方法即可 ```csharp ///系统操作日志事件处理器 单例注入,记录事件日志 public class LogOperationEventHandler : IntegrationEventHandler, ISingleton, IEventLog { /// /// 保存日志 /// /// /// /// public override async Task Run(LogOperationEvent @event, IServiceScope scope) { await scope.ServiceProvider.GetRequiredService>().InsertAsync(@event.GetPayload()!); } } ```