ow
This commit is contained in:
commit
f05d2d215f
678 files changed
+73865
No files matched your search
@@ -0,0 +1,78 @@
|
||||
using CloudBuilder.Core.Application.Builders;
|
||||
using CloudBuilder.Core.Application.Packs;
|
||||
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
||||
using CloudBuilder.Core.DatabaseAccessor;
|
||||
using CloudBuilder.Core.DependencyInjection.EFCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using CloudBuilder.Core.Service;
|
||||
using CloudBuilder.Core.Extensions;
|
||||
|
||||
namespace CloudBuilder.Core.DependencyInjection.EventBuses
|
||||
{
|
||||
[PackLevel(30)]
|
||||
public class EventBusesPack : CloudBuilderPack
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 获取 模块级别
|
||||
/// </summary>
|
||||
public override PackLevel Level => PackLevel.Business;
|
||||
|
||||
/// <summary>
|
||||
/// 获取 模块启动顺序,模块启动的顺序先按级别启动,级别内部再按此顺序启动
|
||||
/// </summary>
|
||||
public override int Order => 3;
|
||||
|
||||
/// <summary>
|
||||
/// 将事件总线的发布者和监听者都添加到依赖注入容器中
|
||||
/// </summary>
|
||||
/// <param name="services">依赖注入服务容器</param>
|
||||
/// <returns></returns>
|
||||
public override IServiceCollection AddServices(IServiceCollection services, CloudBuilderBuilder builder)
|
||||
{
|
||||
var baseType = typeof(IEventPublisher);
|
||||
|
||||
var allAssemblies = CloudBuilderBuilder.GetAssemblies();
|
||||
|
||||
var types = allAssemblies
|
||||
.SelectMany(a => a.DefinedTypes)
|
||||
.Select(type => type.AsType())
|
||||
.Where(type => type != baseType && type.HasImplementedRawGeneric(baseType))
|
||||
.Where(x => x.IsClass).ToList();
|
||||
|
||||
|
||||
foreach (var implementType in types)
|
||||
{
|
||||
services.AddScoped(implementType.GetInterfaces().FirstOrDefault(), implementType);
|
||||
}
|
||||
|
||||
baseType = typeof(IEventSubscriber);
|
||||
|
||||
types = allAssemblies
|
||||
.SelectMany(a => a.DefinedTypes)
|
||||
.Select(type => type.AsType())
|
||||
.Where(type => type != baseType && type.HasImplementedRawGeneric(baseType))
|
||||
.Where(x => x.IsClass).ToList();
|
||||
|
||||
|
||||
foreach (var implementType in types)
|
||||
{
|
||||
services.AddScoped(implementType.GetInterfaces().FirstOrDefault(), implementType);
|
||||
}
|
||||
/*
|
||||
* 取出所有监听服务
|
||||
IEnumerable<ISecurityUserRegisterSubscriber> subscribers = service.ServiceProvider.GetServices<ISecurityUserRegisterSubscriber>();
|
||||
*/
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudBuilder.Core.DependencyInjection.EventBuses
|
||||
{
|
||||
/// <summary>
|
||||
/// 定义事件数据,所有事件都要实现该接口
|
||||
/// </summary>
|
||||
public class EventData
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 事件编号
|
||||
/// </summary>
|
||||
public string? EventId { get; set; }
|
||||
/// <summary>
|
||||
/// 获取 事件发生的时间
|
||||
/// </summary>
|
||||
public DateTime EventTime { get; } = DateTime.Now;
|
||||
/// <summary>
|
||||
/// 获取或设置 事件源,触发事件的对象
|
||||
/// </summary>
|
||||
public object? EventSource { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudBuilder.Core.DependencyInjection.EventBuses
|
||||
{
|
||||
/// <summary>
|
||||
/// 定义事件发布者
|
||||
/// </summary>
|
||||
public interface IEventPublisher
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudBuilder.Core.DependencyInjection.EventBuses
|
||||
{
|
||||
/// <summary>
|
||||
/// 定义事件订阅者
|
||||
/// </summary>
|
||||
public interface IEventSubscriber
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user