Esempio n. 1
0
        public EventStoreSettingsBuilder AddAggregate <T, TId, TFactory>(
            IServiceCollection services,
            string topic,
            int partitions = 1)
            where T : IAggregate <TId>
            where TId : IGuidId
            where TFactory : IAggregateFactory <T, TId>
        {
            if (partitions < 1)
            {
                throw new InvalidOperationException("Partitions must be more then one.");
            }

            var aggregate = new RegisteredAggregate(
                typeof(T),
                typeof(IAggregateFactory <T, TId>),
                typeof(TFactory),
                topic,
                partitions);

            services.AddSingleton(
                typeof(IRepository <T, TId>),
                typeof(EventSourcedRepository <T, TId>));

            _aggregates.Add(aggregate);

            return(this);
        }
Esempio n. 2
0
        public EventStoreSettingsBuilder AddAggregate <T, TId>(
            IServiceCollection services,
            Func <TId, long, IReadOnlyCollection <IDomainEvent>, T> factory,
            string topic)
            where T : IAggregate <TId>
            where TId : IGuidId
        {
            var aggregate = new RegisteredAggregate(
                typeof(T),
                typeof(IAggregateFactory <T, TId>),
                new AggregateFactory <T, TId>(factory),
                topic,
                1);

            services.AddSingleton(
                typeof(IRepository <T, TId>),
                typeof(EventSourcedRepository <T, TId>));

            _aggregates.Add(aggregate);

            return(this);
        }