public static App.AppHost SubscribeeEventHandlers(this App.AppHost host, Assembly assembly)
        {
            var contractsWithImplementation = AppRegistry.EventHandlers[assembly.FullName];
            IEnumerable <Type> contracts    = contractsWithImplementation
                                              .SelectMany(x => x.Contracts)
                                              .ToList();

            var eventBus = EventBus.Current;

            foreach (var contract in contracts)
            {
                var handler = host
                              .ServiceProvider
                              .GetService(contract);

                var genericTypeArguments = contract.GenericTypeArguments;
                var typeName             = genericTypeArguments.First().FullName;

                MethodInfo method  = typeof(EventBus).GetMethod(nameof(EventBus.Subscribe));
                MethodInfo generic = method.MakeGenericMethod(genericTypeArguments);

                var envName = Environment.MachineName;
                generic.Invoke(eventBus, new[] { handler, envName });
            }

            AppRegistry.EventHandlers.Remove(assembly.FullName);

            return(host);
        }
예제 #2
0
        public static App.AppHost SubscribeCommandHandlers(this App.AppHost host, Assembly assembly)
        {
            var contractsWithImplementation = AppRegistry.CommandHandlers[assembly.FullName];
            IEnumerable <Type> contracts    = contractsWithImplementation
                                              .SelectMany(x => x.Contracts)
                                              .ToList();

            var commandBus = CommandBus.Current;

            foreach (var contract in contracts)
            {
                var handler = host
                              .ServiceProvider
                              .GetService(contract);

                MethodInfo method  = typeof(CommandBus).GetMethod(nameof(CommandBus.Subscribe));
                MethodInfo generic = method.MakeGenericMethod(contract.GenericTypeArguments);
                generic.Invoke(commandBus, new[] { handler, null });
            }

            AppRegistry.CommandHandlers.Remove(assembly.FullName);

            return(host);
        }