You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1.0 KiB

事件总线

在这里主要用来发布项目事件用的,更好的解耦代码。目前只有内存事件的实现。

IntegrationEvent

事件父类,所有自定以事件必须要继承这个父类。

//操作日志记录事件
public class LogOperationEvent : IntegrationEvent
{
}

IEventLog

标记事件需要记录执行日志,错误日志所有事件都会记录

IntegrationEventHandler

事件处理器 继承这个类之后实现Run 方法即可

///系统操作日志事件处理器 单例注入,记录事件日志
public class LogOperationEventHandler : IntegrationEventHandler<LogOperationEvent>, ISingleton, IEventLog
{
	/// <summary>
	/// 保存日志
	/// </summary>
	/// <param name="event"></param>
	/// <param name="scope"></param>
	/// <returns></returns>
	public override async Task Run(LogOperationEvent @event, IServiceScope scope)
	{
		await scope.ServiceProvider.GetRequiredService<SqlSugarRepository<LogOperationEntity>>().InsertAsync(@event.GetPayload<LogOperationEntity>()!);
	}
}