예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IEventStoreFacade>((serviceProvider) =>
            {
                var connection = new EventStoreFacade("https://localhost:2113", "tcp://localhost:1113", "admin", "changeit");
                return(connection);
            });

            ILogger log = new LoggerConfiguration()
                          .MinimumLevel.Error()
                          .WriteTo.Debug()
                          .WriteTo.Console()
                          .CreateLogger();

            EventDrivenThinking.Logging.LoggerFactory.Init(log);
            services.AddSingleton <ILogger>(log);

            var config = services.AddEventDrivenThinking(Logger.None, x =>
            {
                x.AddAssemblies(typeof(Startup).Assembly);
                x.Slices.SelectAll()
                .Queries.FromEventStore()
                .Events.UseEventStore()
                .Aggregates.BindCarter().WriteToEventStore()
                .Processors.SubscribeFromEventStore()
                .Projections.UseEventStore();
            });

            services.AddCarter(configurator: config.GetCarterConfigurator());
            services.AddSignalR();

            services.AddSingleton <UserModel>();
        }
        public async Task StreamRevisionWorksSameForTcpAndHttp()
        {
            EventStoreFacade f = ConnectEs();

            Guid   g  = Guid.NewGuid();
            string sm = $"test-{g}";
            List <ResolvedEvent> events_1 = new List <ResolvedEvent>();
            List <ResolvedEvent> events_2 = new List <ResolvedEvent>();
            StreamRevision       sr       = new StreamRevision(1);

            await f.AppendToStreamAsync(sm, AnyStreamRevision.Any, TestEvents(new RoomAdded(), new RoomAdded()));

            await foreach (var i in f.ReadStreamAsync(Direction.Forwards, sm, StreamRevision.Start, 2))
            {
                events_1.Add(i);
            }

            f.IsTcp = !f.IsTcp;

            await foreach (var i in f.ReadStreamAsync(Direction.Forwards, sm, StreamRevision.Start, 2))
            {
                events_2.Add(i);
            }

            for (int i = 0; i < 2; i++)
            {
                var e1 = events_1[i];
                var e2 = events_2[i];

                e1.OriginalEventNumber.Should().Be(e2.OriginalEventNumber);
            }
        }
        private EventStoreFacade ConnectEs()
        {
            EventStoreFacade es = new EventStoreFacade("https://localhost:2113",
                                                       "tcp://localhost:1113", "admin", "changeit");

            return(es);
        }
예제 #4
0
        private static async Task <IEventStoreFacade> Connect()
        {
            var client = new EventStoreFacade("https://*****:*****@localhost:1113"));
            //await connection.ConnectAsync();
            //return connection;
        }
        public async Task SubscribeFromStart()
        {
            EventStoreFacade f = ConnectEs();

            Guid   g  = Guid.NewGuid();
            string sm = $"test-{g}";
            List <ResolvedEvent> events = new List <ResolvedEvent>();
            StreamRevision       sr     = new StreamRevision(0);

            await f.SubscribeToStreamAsync(sm, sr, async (s, r, c) => { events.Add(r); }, null, true);

            await f.AppendToStreamAsync(sm, AnyStreamRevision.Any, TestEvents(new RoomAdded()));

            await Task.Delay(1000);

            events.Should().HaveCount(1);
        }
예제 #6
0
        public void ConfigureServices(IServiceCollection services)
        {
            //this.sentry = Sentry.SentrySdk.Init( opt => opt.Dsn = new Dsn("http://949295c75e454b578e5336dce15d4af4@localhost:9000/1"));

            ILogger log = new LoggerConfiguration()
                          .MinimumLevel.Error()
                          .WriteTo.Debug()
                          .CreateLogger();

            log.Information("Configuring services...");
            Assembly[] assemblies = new[]
            {
                typeof(HotelAggregate).Assembly
            };
            services.AddSingleton <ILogger>(log);
            var config = services.AddEventDrivenThinking(log, c =>
            {
                c.AddAssemblies(assemblies);

                c.Slices.SelectAll()
                .Aggregates.BindCarter().WriteToEventStore()
                .Projections.UseEventStore(true)
                .Processors.SubscribeFromEventStore()
                .Events.UseEventStore()
                .Queries.FromEventStore()
                .Commands.ToCommandHandler();
            });

            services.AddSingleton <IEventStoreFacade>((serviceProvider) =>
            {
                var connection = new EventStoreFacade("https://localhost:2113", "tcp://localhost:1113", "admin", "changeit");
                return(connection);
            });

            /// FOR NOW
            foreach (var modelType in assemblies.SelectMany(x => x.GetTypes())
                     .Where(x => typeof(IModel).IsAssignableFrom(x) && !x.IsAbstract && !x.IsInterface))
            {
                services.AddSingleton(modelType);
            }


            foreach (var i in config.Services.QuerySchemaRegister)
            {
                services.AddTransient(
                    typeof(IQueryHandler <, ,>).MakeGenericType(i.Type, i.ModelType, i.ResultType), i.QueryHandlerType);

                //foreach (var p in i.StreamPartitioners)
                //    services.AddTransient(typeof(IQueryPartitioner<>).MakeGenericType(i.Type), p);

                foreach (var p in i.QueryPartitioners)
                {
                    services.AddTransient(typeof(IQueryPartitioner <>).MakeGenericType(i.Type), p);
                }
            }

            services.AddSingleton <DispatcherQueue>();
            services.AddSingleton <IRoomAvailabilityModel, RoomAvailabilityModel>();
            services.AddSingleton <IModelFactory, ModelFactory>();

            services.AddCarter(configurator: config.GetCarterConfigurator());
            services.AddSignalR()
            .AddNewtonsoftJsonProtocol();

            log.Information("Configuring done.");
        }