Пример #1
0
 public static IDomainContainer AddMetadataProviders(
     this IDomainContainer domainContainer,
     params Type[] metadataProviderTypes)
 {
     return(domainContainer
            .AddMetadataProviders((IEnumerable <Type>)metadataProviderTypes));
 }
        public static IDomainContainer AddQueryHandlers(
            this IDomainContainer domainContainer,
            IEnumerable <Type> queryHandlerTypes)
        {
            foreach (var queryHandlerType in queryHandlerTypes)
            {
                var t = queryHandlerType;
                if (t.GetTypeInfo().IsAbstract)
                {
                    continue;
                }
                var queryHandlerInterfaces = t
                                             .GetTypeInfo()
                                             .GetInterfaces()
                                             .Where(IsQueryHandlerInterface)
                                             .ToList();
                if (!queryHandlerInterfaces.Any())
                {
                    throw new ArgumentException($"Type '{t.PrettyPrint()}' is not an '{typeof(IQueryHandler<,>).PrettyPrint()}'");
                }

                foreach (var queryHandlerInterface in queryHandlerInterfaces)
                {
                    domainContainer.ServiceCollection.AddTransient(queryHandlerInterface, t);
                }
            }

            return(domainContainer);
        }
Пример #3
0
        public static IDomainContainer AddSubscribers(
            this IDomainContainer domainContainer,
            IEnumerable <Type> subscribeSynchronousToTypes)
        {
            foreach (var subscribeSynchronousToType in subscribeSynchronousToTypes)
            {
                var t = subscribeSynchronousToType;
                if (t.GetTypeInfo().IsAbstract)
                {
                    continue;
                }

                var subscribeTos = t
                                   .GetTypeInfo()
                                   .GetInterfaces()
                                   .Where(IsSubscriberInterface)
                                   .ToList();
                if (!subscribeTos.Any())
                {
                    throw new ArgumentException($"Type '{t.PrettyPrint()}' is not an '{ISubscribeSynchronousToType.PrettyPrint()}', '{ISubscribeAsynchronousToType.PrettyPrint()}' or '{ISubscribeSynchronousToAllType.PrettyPrint()}'");
                }

                foreach (var subscribeTo in subscribeTos)
                {
                    domainContainer.ServiceCollection.AddTransient(subscribeTo, t);
                }
            }

            return(domainContainer);
        }
Пример #4
0
        public static IDomainContainer AddCommandHandlers(
            this IDomainContainer domainContainer,
            IEnumerable <Type> commandHandlerTypes)
        {
            foreach (var commandHandlerType in commandHandlerTypes)
            {
                var t = commandHandlerType;
                if (t.GetTypeInfo().IsAbstract)
                {
                    continue;
                }
                var handlesCommandTypes = t
                                          .GetTypeInfo()
                                          .GetInterfaces()
                                          .Where(IsCommandHandlerInterface)
                                          .ToList();
                if (!handlesCommandTypes.Any())
                {
                    throw new ArgumentException($"Type '{commandHandlerType.PrettyPrint()}' does not implement '{typeof(ICommandHandler<,,,>).PrettyPrint()}'");
                }

                foreach (var handlesCommandType in handlesCommandTypes)
                {
                    domainContainer.ServiceCollection.AddTransient(handlesCommandType, t);
                }
            }

            return(domainContainer);
        }
 public static IDomainContainer RegisterServices(
     this IDomainContainer domainContainer,
     Action <IServiceCollection> registerServices)
 {
     registerServices(domainContainer.ServiceCollection);
     return(domainContainer);
 }
 public static IDomainContainer AddQueryHandler <TQueryHandler, TQuery, TResult>(
     this IDomainContainer domainContainer)
     where TQueryHandler : class, IQueryHandler <TQuery, TResult>
     where TQuery : IQuery <TResult>
 {
     domainContainer.ServiceCollection
     .AddTransient <IQueryHandler <TQuery, TResult>, TQueryHandler>();
     return(domainContainer);
 }
Пример #7
0
        public static IDomainContainer AddMetadataProvider <TMetadataProvider>(
            this IDomainContainer domainContainer)
            where TMetadataProvider : class, IMetadataProvider
        {
            domainContainer
            .ServiceCollection
            .AddTransient <IMetadataProvider, TMetadataProvider>();

            return(domainContainer);
        }
Пример #8
0
 public static IDomainContainer AddSubscriber <TAggregate, TIdentity, TEvent, TSubscriber>(
     this IDomainContainer domainContainer)
     where TAggregate : IAggregateRoot <TIdentity>
     where TIdentity : IIdentity
     where TEvent : IAggregateEvent <TAggregate, TIdentity>
     where TSubscriber : class, ISubscribeSynchronousTo <TAggregate, TIdentity, TEvent>
 {
     domainContainer.ServiceCollection
     .AddTransient <ISubscribeSynchronousTo <TAggregate, TIdentity, TEvent>, TSubscriber>();
     return(domainContainer);
 }
        public static IDomainContainer AddCommands(
            this IDomainContainer domainContainer,
            Assembly fromAssembly,
            Predicate <Type> predicate)
        {
            predicate = predicate ?? (t => true);
            var commandTypes = fromAssembly
                               .GetTypes()
                               .Where(t => !t.GetTypeInfo().IsAbstract&& typeof(ICommand).GetTypeInfo().IsAssignableFrom(t))
                               .Where(t => predicate(t));

            return(domainContainer.AddCommands(commandTypes));
        }
Пример #10
0
        public static IDomainContainer AddEvents(
            this IDomainContainer domainContainer,
            Assembly fromAssembly,
            Predicate <Type> predicate = null)
        {
            predicate = predicate ?? (t => true);
            var aggregateEventTypes = fromAssembly
                                      .GetTypes()
                                      .Where(t => !t.GetTypeInfo().IsAbstract&& typeof(IAggregateEvent).GetTypeInfo().IsAssignableFrom(t))
                                      .Where(t => predicate(t));

            return(domainContainer.AddEvents(aggregateEventTypes));
        }
        public static IDomainContainer AddJobs(
            this IDomainContainer domainContainer,
            Assembly fromAssembly,
            Predicate <Type> predicate = null)
        {
            predicate = predicate ?? (t => true);
            var jobTypes = fromAssembly
                           .GetTypes()
                           .Where(type => !type.GetTypeInfo().IsAbstract&& type.IsAssignableTo <IJob>())
                           .Where(t => !t.HasConstructorParameterOfType(i => i.IsAssignableTo <IJob>()))
                           .Where(t => predicate(t));

            return(domainContainer.AddJobs(jobTypes));
        }
 public static IDomainContainer AddDefaults(
     this IDomainContainer domainContainer,
     Assembly fromAssembly,
     Predicate <Type> predicate = null)
 {
     return(domainContainer
            .AddEvents(fromAssembly, predicate)
            .AddJobs(fromAssembly, predicate)
            .AddCommands(fromAssembly, predicate)
            .AddCommandHandlers(fromAssembly, predicate)
            .AddMetadataProviders(fromAssembly, predicate)
            .AddSubscribers(fromAssembly, predicate)
            .AddQueryHandlers(fromAssembly, predicate));
 }
Пример #13
0
        public static IDomainContainer AddCommandHandlers(
            this IDomainContainer domainContainer,
            Assembly fromAssembly,
            Predicate <Type> predicate = null)
        {
            predicate = predicate ?? (t => true);
            var commandHandlerTypes = fromAssembly
                                      .GetTypes()
                                      .Where(t => t.GetTypeInfo().GetInterfaces().Any(IsCommandHandlerInterface))
                                      .Where(t => !t.HasConstructorParameterOfType(IsCommandHandlerInterface))
                                      .Where(t => predicate(t));

            return(domainContainer.AddCommandHandlers(commandHandlerTypes));
        }
Пример #14
0
        public static IDomainContainer AddMetadataProviders(
            this IDomainContainer domainContainer,
            Assembly fromAssembly,
            Predicate <Type> predicate = null)
        {
            predicate = predicate ?? (t => true);
            var metadataProviderTypes = fromAssembly
                                        .GetTypes()
                                        .Where(IsMetadataProvider)
                                        .Where(t => !t.HasConstructorParameterOfType(IsMetadataProvider))
                                        .Where(t => predicate(t));

            return(domainContainer.AddMetadataProviders(metadataProviderTypes));
        }
        public static IDomainContainer AddQueryHandlers(
            this IDomainContainer domainContainer,
            Assembly fromAssembly,
            Predicate <Type> predicate = null)
        {
            predicate = predicate ?? (t => true);
            var subscribeSynchronousToTypes = fromAssembly
                                              .GetTypes()
                                              .Where(t => t.GetTypeInfo().GetInterfaces().Any(IsQueryHandlerInterface))
                                              .Where(t => !t.HasConstructorParameterOfType(IsQueryHandlerInterface))
                                              .Where(t => predicate(t));

            return(domainContainer
                   .AddQueryHandlers(subscribeSynchronousToTypes));
        }
Пример #16
0
        public static IDomainContainer AddMetadataProviders(
            this IDomainContainer domainContainer,
            IEnumerable <Type> metadataProviderTypes)
        {
            foreach (var t in metadataProviderTypes)
            {
                if (t.GetTypeInfo().IsAbstract)
                {
                    continue;
                }
                if (!t.IsMetadataProvider())
                {
                    throw new ArgumentException($"Type '{t.PrettyPrint()}' is not an '{typeof(IMetadataProvider).PrettyPrint()}'");
                }

                domainContainer.ServiceCollection.AddTransient(typeof(IMetadataProvider), t);
            }
            return(domainContainer);
        }
 public static IDomainContainer AddJobs(
     this IDomainContainer domainContainer,
     params Type[] jobTypes)
 {
     return(domainContainer.AddJobs(jobTypes));
 }
Пример #18
0
 public static IDomainContainer AddSubscribers(
     this IDomainContainer domainContainer,
     params Type[] types)
 {
     return(domainContainer.AddSubscribers((IEnumerable <Type>)types));
 }
Пример #19
0
 public static IDomainContainer AddCommandHandlers(
     this IDomainContainer domainContainer,
     params Type[] commandHandlerTypes)
 {
     return(domainContainer.AddCommandHandlers((IEnumerable <Type>)commandHandlerTypes));
 }
Пример #20
0
 public static IDomainContainer AddEvents(
     this IDomainContainer domainContainer,
     params Type[] aggregateEventTypes)
 {
     return(domainContainer.AddEvents((IEnumerable <Type>)aggregateEventTypes));
 }
 public static IDomainContainer AddQueryHandlers(
     this IDomainContainer domainContainer,
     params Type[] queryHandlerTypes)
 {
     return(domainContainer.AddQueryHandlers((IEnumerable <Type>)queryHandlerTypes));
 }
 public static IDomainContainer AddCommands(
     this IDomainContainer domainContainer,
     params Type[] commandTypes)
 {
     return(domainContainer.AddCommands(commandTypes));
 }
Пример #23
0
 public EventDispatcher(IDomainContainer container)
 {
     _container = container;
 }