예제 #1
0
 internal static void ConfigureInMemoryEventBus(Bootstrapper bootstrapper, InMemoryEventBusConfiguration configuration, string[] excludedEventsDLLs, BootstrappingContext ctx)
 {
     InMemoryEventBus.InitHandlersCollection(excludedEventsDLLs);
     if (ctx.IsServiceRegistered(BootstrapperServiceType.IoC))
     {
         bootstrapper.AddIoCRegistration(new TypeRegistration(typeof(InMemoryEventBus), typeof(IDomainEventBus), typeof(InMemoryEventBus)));
         if (configuration != null)
         {
             bootstrapper.AddIoCRegistration(new InstanceTypeRegistration(configuration, typeof(InMemoryEventBusConfiguration)));
         }
     }
     bootstrapper.AddNotifications(PerformEventChecksAccordingToBootstrapperParameters(ctx, configuration));
 }
예제 #2
0
        /// <summary>
        /// Configure the bootstrapper to use InMemory buses for dispatching events.
        /// </summary>
        /// <param name="bootstrapper">Instance of boostrapper.</param>
        /// <param name="configuration">Configuration to use for in memory event bus.</param>
        /// <param name="excludedEventsDLLs">DLLs name to exclude from auto-configuration into IoC
        /// (IAutoRegisterType will be ineffective).</param>
        public static Bootstrapper UseInMemoryEventBus(this Bootstrapper bootstrapper, InMemoryEventBusConfiguration configuration = null, params string[] excludedEventsDLLs)
        {
            var service = InMemoryBusesBootstrappService.Instance;

            service.BootstrappAction += (ctx) =>
            {
                InMemoryEventBus.InitHandlersCollection(excludedEventsDLLs);
                if (ctx.IsServiceRegistered(BootstrapperServiceType.IoC))
                {
                    bootstrapper.AddIoCRegistration(new TypeRegistration(typeof(InMemoryEventBus), typeof(IDomainEventBus), typeof(InMemoryEventBus)));
                    if (configuration != null)
                    {
                        bootstrapper.AddIoCRegistration(new InstanceTypeRegistration(configuration, typeof(InMemoryEventBusConfiguration)));
                    }
                }
                bootstrapper.AddNotifications(PerformEventChecksAccordingToBootstrapperParameters(ctx, configuration));
            };
            if (!bootstrapper.RegisteredServices.Any(s => s == service))
            {
                bootstrapper.AddService(service);
            }
            return(bootstrapper);
        }
예제 #3
0
        private static IEnumerable <BootstrapperNotification> PerformEventChecksAccordingToBootstrapperParameters(BootstrappingContext ctx,
                                                                                                                  InMemoryEventBusConfiguration configuration)
        {
            var notifs = new List <BootstrapperNotification>();

            foreach (var evtType in _allTypes.Where(t => typeof(IDomainEvent).IsAssignableFrom(t) && t.IsClass && !t.IsAbstract).AsParallel())
            {
                var handlers = _allTypes.Where(t => typeof(IDomainEventHandler <>).MakeGenericType(evtType).IsAssignableFrom(t)).ToList();
                if (handlers.Count == 0)
                {
                    if (ctx.CheckOptimal)
                    {
                        notifs.Add(
                            new BootstrapperNotification(
                                BootstrapperNotificationType.Warning,
                                $"Your project doesn't contain any handler for event type {evtType.FullName}, which is generally not desired (you forget to add implementation of it). When implementing it, don't forget to allow InMemoryEventBus to be able to retrieve it (by adding it to your IoC container or by creating a parameterless constructor to allow to create it by reflection). If this is desired, you can ignore this warning.",
                                typeof(InMemoryEventBus))
                            );
                    }
                }
                var isHandlerCritical = handlers.Any(h => h.IsDefined(typeof(CriticalHandlerAttribute)));
                if (isHandlerCritical && configuration?.ParallelHandling.Any(e => e == evtType) == true)
                {
                    notifs.Add(
                        new BootstrapperNotification(
                            BootstrapperNotificationType.Warning,
                            $"There are multiples handlers for event type {evtType.FullName}, and at least one of them is marked as 'critical', meaning next ones shouldn't be called if critical failed. However, your configuration for this specific event type says they're allowed to run in parallel. This configuration *cannot* ensure that critical handlers will block next ones, you should review your configuration (by setting ShouldWait to true) or remove CriticalHandler attribute, which can't be ensured in this case.",
                            typeof(InMemoryEventBus))
                        );
                }
            }
            return(notifs.AsEnumerable());
        }
예제 #4
0
        /// <summary>
        /// Configure the bootstrapper to use InMemory buses for dispatching events.
        /// </summary>
        /// <param name="bootstrapper">Instance of boostrapper.</param>
        /// <param name="configuration">Configuration to use for in memory event bus.</param>
        /// <param name="excludedEventsDLLs">DLLs name to exclude from auto-configuration into IoC
        /// (IAutoRegisterType will be ineffective).</param>
        public static Bootstrapper UseInMemoryEventBus(this Bootstrapper bootstrapper, InMemoryEventBusConfiguration configuration = null, params string[] excludedEventsDLLs)
        {
            var service = InMemoryBusesBootstrappService.Instance;

            service.BootstrappAction += (ctx) =>
            {
                ConfigureInMemoryEventBus(bootstrapper, configuration, excludedEventsDLLs, ctx);
            };
            if (!bootstrapper.RegisteredServices.Any(s => s == service))
            {
                bootstrapper.AddService(service);
            }
            return(bootstrapper);
        }