Exemplo n.º 1
0
        private static void ApplySetup(CqrsConfigurationSetup config)
        {
            Container = config.Container;
            Container.RegisterSingle(Container);

            if (config.IsUsingDefaultDispatchers)
            {
                Container.Register <IQueryDispatcher, QueryDispatcher>();
                Container.Register <ICommandDispatcher, CommandDispatcher>();
            }

            if (!config.Assemblies.Any())
            {
                return;
            }

            var queryHandlerType   = typeof(IQueryHandler <,>);
            var commandHandlerType = typeof(ICommandHandler <>);
            var handlers           = from a in config.Assemblies
                                     from t in a.GetExportedTypes()
                                     from i in t.GetInterfaces().Where(i => i.IsGenericType)
                                     let generic = i.GetGenericTypeDefinition()
                                                   where generic == queryHandlerType || generic == commandHandlerType
                                                   select new { Implementation = t, Contract = i };

            foreach (var handler in handlers)
            {
                Container.Register(handler.Contract, handler.Implementation);
            }
        }
Exemplo n.º 2
0
        private static void ApplySetup(CqrsConfigurationSetup config)
        {
            Container = config.Container;
            Container.RegisterSingle(Container);

            if (config.IsUsingDefaultDispatchers)
            {
                Container.Register<IQueryDispatcher, QueryDispatcher>();
                Container.Register<ICommandDispatcher, CommandDispatcher>();
            }

            if (!config.Assemblies.Any())
                return;

            var queryHandlerType = typeof(IQueryHandler<,>);
            var commandHandlerType = typeof(ICommandHandler<>);
            var handlers = from a in config.Assemblies
                           from t in a.GetExportedTypes()
                           from i in t.GetInterfaces().Where(i => i.IsGenericType)
                           let generic = i.GetGenericTypeDefinition()
                           where generic == queryHandlerType || generic == commandHandlerType
                           select new { Implementation = t, Contract = i };

            foreach (var handler in handlers)
            {
                Container.Register(handler.Contract, handler.Implementation);
            }
        }
Exemplo n.º 3
0
        public static void Setup(Action<CqrsConfigurationSetup> action)
        {
            var config = new CqrsConfigurationSetup();
            action(config);

            if (!IsValid(config))
                throw Exceptions.InvalidConfigurationException();

            ApplySetup(config);
        }
Exemplo n.º 4
0
        public static void Setup(Action <CqrsConfigurationSetup> action)
        {
            var config = new CqrsConfigurationSetup();

            action(config);

            if (!IsValid(config))
            {
                throw Exceptions.InvalidConfigurationException();
            }

            ApplySetup(config);
        }
Exemplo n.º 5
0
 private static bool IsValid(CqrsConfigurationSetup config) => config.Container != null && config.Assemblies.Any();
Exemplo n.º 6
0
 private static bool IsValid(CqrsConfigurationSetup config) => config.Container != null && config.Assemblies.Any();