Пример #1
0
        public static IZaabyServer UseEventBus(this IZaabyServer zaabyServer)
        {
            AllTypes = zaabyServer.AllTypes;
            var interfaceType = typeof(IIntegrationEventBus);
            var eventBusType  =
                AllTypes.FirstOrDefault(type => interfaceType.IsAssignableFrom(type) && type.IsClass);

            if (eventBusType == null)
            {
                return(zaabyServer);
            }
            zaabyServer.AddSingleton(interfaceType, eventBusType);
            zaabyServer.RegisterServiceRunner(interfaceType, eventBusType);
            return(zaabyServer);
        }
        public static IZaabyServer UseDomainEventHandler(this IZaabyServer zaabyServer)
        {
            var domainEventHandlerQuery = AllTypes.Where(type => type.IsClass);

            domainEventHandlerQuery = domainEventHandlerQuery.Where(type =>
                                                                    type.BaseType != null &&
                                                                    type.BaseType.IsGenericType &&
                                                                    type.BaseType.GetGenericTypeDefinition() == typeof(DomainEventHandler <>));

            var domainEventHandlers = domainEventHandlerQuery.ToList();

            domainEventHandlers.ForEach(domainEventHandler =>
            {
                zaabyServer.AddSingleton(domainEventHandler, domainEventHandler);
                zaabyServer.RegisterServiceRunner(domainEventHandler);
            });
            return(zaabyServer);
        }