예제 #1
0
        /// <summary>
        /// 添加事件服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="assemblies"></param>
        private static void AddEvent(this IServiceCollection services, params Assembly[] assemblies)
        {
            var  eventHandlerHelper = new EventHandlerHelper();
            Type eventHandlerType   = typeof(IEventHandler);

            foreach (Assembly assembly in assemblies)
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (!eventHandlerType.IsAssignableFrom(type))
                    {
                        continue;
                    }
                    if (eventHandlerHelper.TryAddEventHandler(type))
                    {
                        services.AddTransient(type);
                    }
                }
            }
            services.AddSingleton(eventHandlerHelper);
        }
예제 #2
0
 public EventBusImpl(EventHandlerHelper eventHandlerHelper, IServiceProvider serviceProvider)
 {
     _eventHandlerHelper = eventHandlerHelper;
     _serviceProvider    = serviceProvider;
 }