public static OzzyDomainBuilder <TDomain> AddOzzyDomain <TDomain>(this IServiceCollection services, Action <OzzyDomainOptionsBuilder <TDomain> > configureOptions) where TDomain : IOzzyDomainModel
        {
            var builder        = new OzzyDomainBuilder <TDomain>(services);
            var optionsBuilder = new OzzyDomainOptionsBuilder <TDomain>(builder);

            configureOptions(optionsBuilder);

            builder.Services.TryAddTypeSpecificSingleton <TDomain, DomainEventsLoop>(sp =>
            {
                var reader     = sp.GetTypeSpecificService <TDomain, IPeristedEventsReader>();
                var processors = sp.GetTypeSpecificServicesCollection <TDomain, IDomainEventsProcessor>();
                return(new DomainEventsLoop(reader, processors));
            });
            builder.Services.TryAddSingleton <IBackgroundProcess>(sp =>
            {
                var loop            = sp.GetTypeSpecificService <TDomain, DomainEventsLoop>();
                var recieverFactory = sp.GetTypeSpecificService <TDomain, IFastEventRecieverFactory>();
                return(new MessageLoopProcess(loop, recieverFactory));
            });

            builder.Services.TryAddTypeSpecificSingleton <TDomain, IFastEventPublisher>(NullEventsPublisher.Instance);
            builder.Services.TryAddTypeSpecificSingleton <TDomain, Func <IFastEventPublisher> >(sp => () => NullEventsPublisher.Instance);
            builder.Services.TryAddSingleton <DefaultSagaFactory <TDomain> >();
            builder.Services.TryAddTypeSpecificSingleton <TDomain, ISagaFactory>(sp => sp.GetService <DefaultSagaFactory <TDomain> >());
            return(builder);
        }
        public static OzzyDomainBuilder <TDomain> UseEntityFramework <TDomain>(this OzzyDomainBuilder <TDomain> builder,
                                                                               Action <DbContextOptionsBuilder> optionsAction = null)
            where TDomain : AggregateDbContext
        {
            builder.Services.AddDbContext <TDomain>(optionsAction, ServiceLifetime.Transient);
            builder.Services.TryAddScoped <ScopedRegistration <TDomain> >();
            builder.Services.TryAddSingleton <Func <TDomain> >(sp => () => sp.GetService <TDomain>());

            builder.Services.TryAddSingleton <EfEventsReader <TDomain> >();
            builder.Services.TryAddTypeSpecificSingleton <TDomain, IPeristedEventsReader>(sp => sp.GetService <EfEventsReader <TDomain> >());

            builder.Services.TryAddSingleton <EfDomainEventsManager <TDomain> >();
            builder.Services.AddTypeSpecificSingleton <TDomain, IDomainEventsManager>(sp => sp.GetService <EfDomainEventsManager <TDomain> >());

            builder.Services.TryAddSingleton <EfSagaRepository <TDomain> >();
            builder.Services.TryAddTypeSpecificSingleton <TDomain, ISagaRepository>(sp =>
            {
                var contextFactory = sp.GetService <Func <TDomain> >();
                var sagaFactory    = sp.GetTypeSpecificService <TDomain, ISagaFactory>();
                return(new EfSagaRepository <TDomain>(contextFactory, sagaFactory));
            });

            builder.Services.AddTypeSpecificSingleton <TDomain, IDistributedLockService>(sp => new EfDistributedLockService(sp.GetService <Func <TDomain> >()));
            builder.Services.AddTypeSpecificSingleton <TDomain, IQueueRepository>(sp => new EfQueueRepository(sp.GetService <Func <TDomain> >(), db => db.Queues, db => db.DeadLetters));

            return(builder);
        }
Esempio n. 3
0
 public OzzyDomainOptionsBuilder(OzzyDomainBuilder <TDomain> domainBuilder)
 {
     _domainBuilder = domainBuilder;
 }