Example #1
0
 /// <summary>
 /// Use default changes bus - <see cref="InMemoryChangesBus"/>
 /// </summary>
 public static ErdenConfig UseDefaultChangeBus(this ErdenConfig config)
 {
     var inMemoryChangesBus = new InMemoryChangesBus();
     config.Services.AddSingleton<IChangesBus>(provider => inMemoryChangesBus);
     config.Services.AddSingleton<IChangeHandlerRegistrator>(provider => inMemoryChangesBus);
     return config;
 }
Example #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Erden CQRS example");
            Console.WriteLine();
            services = new ServiceCollection();
            var cqrsConfiguration = new ErdenConfig(services)
                                    .AddCqrs()
                                    .UseDefaultCommandBus()
                                    .UseDefaultDataStorage();

            cqrsConfiguration.Build();

            var          provider = services.BuildServiceProvider();
            ICommandBus  bus      = provider.GetService <ICommandBus>();
            IDataStorage storage  = provider.GetService <IDataStorage>();

            bus.Send(new ExampleCommand()).Wait();
            var result = storage.Retrieve(new ExampleQuery()).Result;

            Console.WriteLine($"Query result is {result}");

            Console.WriteLine();
            Console.WriteLine("Press any button to exit");
            Console.ReadKey(false);
        }
Example #3
0
 /// <summary>
 /// Use default fetch source - <see cref="InMemoryStorage"/>
 /// </summary>
 public static ErdenConfig UseDefaultFetchSource(this ErdenConfig config)
 {
     var inMemoryStorage = new InMemoryStorage();
     config.Services.AddSingleton<IStorage>(provider => inMemoryStorage);
     config.Services.AddSingleton<IFetchHandlerRegistrator>(provider => inMemoryStorage);
     return config;
 }
Example #4
0
        /// <summary>
        /// Use default in memory data storage
        /// </summary>
        /// <returns></returns>
        public static ErdenConfig UseDefaultDataStorage(this ErdenConfig config)
        {
            var inMemoryDataStorage = new InMemoryDataStorage();

            config.Services.AddSingleton <IDataStorage>(provider => inMemoryDataStorage);
            config.Services.AddSingleton <IQueryHandlerRegistrator>(provider => inMemoryDataStorage);
            return(config);
        }
Example #5
0
        // <summary>
        /// Use default in memory command bus
        /// </summary>
        public static ErdenConfig UseDefaultCommandBus(this ErdenConfig config)
        {
            var inMemoryCommandBus = new InMemoryCommandBus();

            config.Services.AddSingleton <ICommandHandlerRegistrator>(provider => inMemoryCommandBus);
            config.Services.AddSingleton <ICommandBus>(provider => inMemoryCommandBus);
            return(config);
        }
Example #6
0
        public static ErdenConfig UseDefaultEventBus(this ErdenConfig config)
        {
            var inMemoryEventBus = new InMemoryEventBus();

            config.Services.AddSingleton <IEventHandlerRegistrator>(provider => inMemoryEventBus);
            config.Services.AddSingleton <IEventPublisher>(provider => inMemoryEventBus);
            return(config);
        }
        private ServiceProvider Configure()
        {
            var services = new ServiceCollection();
            var config   = new ErdenConfig(services)
                           .AddEventSourcing()
                           .UseDefaultEventBus();

            config.Build();

            return(services.BuildServiceProvider());
        }
        private ServiceProvider Configure()
        {
            var services = new ServiceCollection();
            var config   = new ErdenConfig(services)
                           .AddCqrs()
                           .UseDefaultCommandBus()
                           .UseDefaultDataStorage();

            config.Build();

            return(services.BuildServiceProvider());
        }
Example #9
0
        public void ConfigureServices(IServiceCollection services)
        {
            OptionsConfigurationServiceCollectionExtensions.Configure <EventStoreSettings>(services, Configuration.GetSection("EventStore"));
            services.AddMvc();

            var erden = new ErdenConfig(services)
                        .UseDefaultCommandBus()
                        .UseDefaultDataStorage()
                        .UseDefaultEventBus()
                        .AddEventStoreTarget <EventStoreTarget>();

            erden.Build();
        }
Example #10
0
        private ServiceProvider Configure()
        {
            LoggerFactory factory  = new LoggerFactory();
            var           services = new ServiceCollection();
            var           config   = new ErdenConfig(services)
                                     .AddEventSourcing()
                                     .UseDefaultEventBus()
                                     .AddEventStoreTarget <InMemoryEventStore>();

            config.Build();
            new ErdenConfig(services).AddDomain().Build();

            return(services.BuildServiceProvider());
        }
Example #11
0
 /// <summary>
 /// Add CQRS
 /// </summary>
 public static ErdenConfig AddCqrs(this ErdenConfig config)
 {
     config.AddToRegistration(typeof(ICommandHandler <>), typeof(ICommandHandlerRegistrator), "Execute");
     config.AddToRegistration(typeof(IQueryHandler <,>), typeof(IQueryHandlerRegistrator), "Execute");
     return(config);
 }
Example #12
0
 /// <summary>
 /// Add DAL
 /// </summary>
 public static ErdenConfig AddDal(this ErdenConfig config)
 {
     config.AddToRegistration(typeof(IChangeHandler<>), typeof(IChangeHandlerRegistrator), "Execute");
     config.AddToRegistration(typeof(IFetchHandler<,>), typeof(IFetchHandlerRegistrator), "Execute");
     return config;
 }
Example #13
0
 public static ErdenConfig AddEventSourcing(this ErdenConfig config)
 {
     config.AddToRegistration(typeof(IEventHandler <>), typeof(IEventHandlerRegistrator), "Handle");
     return(config);
 }
Example #14
0
 public static ErdenConfig AddEventStoreTarget <T>(this ErdenConfig config) where T : class, IEventStore
 {
     config.Services.AddSingleton <IEventStore, T>();
     return(config);
 }
Example #15
0
 public static ErdenConfig AddDomain(this ErdenConfig config)
 {
     config.Services.AddSingleton <IAggregateStorage, AggregateStorage>();
     config.Services.AddSingleton <ISession, Session>();
     return(config);
 }