// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var esConnection = EventStoreConnection.Create( Configuration["eventStore:connectionString"], ConnectionSettings.Create().KeepReconnecting(), Environment.ApplicationName); var store = new EsAggregateStore(esConnection); services.AddSingleton(esConnection); services.AddSingleton <IAggregateStore>(store); services.AddSingleton(new ClassifiedAdsApplicationService( store, new FixedCurrencyLookup())); services.AddSingleton <IHostedService, HostedService>(); services.AddMvc(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "ClassifiedAds", Version = "v1" }); }); }
public void ConfigureServices(IServiceCollection services) { services.AddControllers(); var esConnection = EventStoreConnection.Create( Configuration["eventStore:connectionString"], ConnectionSettings.Create().KeepReconnecting(), "test-workshop"); var store = new EsAggregateStore(esConnection); var mongoDb = GetMongo(Configuration["mongoDb:connectionString"]); services.AddSingleton <IAggregateStore>(store); services.AddSingleton <ScreeningAppService>(); services.AddSingleton <IHostedService>( new EventStoreHostedService(esConnection, new ScheduledScreeningProjection(mongoDb) ) ); services.AddSingleton <GetMovieDuration>(s => _ => Task.FromResult(120) ); services.AddSingleton <GetUtcNow>(s => () => DateTimeOffset.Now); services.AddSingleton <GetTheaterCapacity>(s => id => Task.FromResult(100)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var esConnection = EventStoreConnection.Create( Configuration["eventStore:connectionString"], ConnectionSettings.Create().KeepReconnecting(), Environment.ApplicationName); var store = new EsAggregateStore(esConnection); services.AddSingleton(esConnection) .AddSingleton <IAggregateStore>(store) .AddSingleton <IApplicationService, DailyBudgetsCommandService>() .AddControllers(); var dailybudgetItems = new List <ReadModels.DailyBudgets>(); services.AddSingleton <IEnumerable <ReadModels.DailyBudgets> >(dailybudgetItems); var subscription = new EsSubscription(esConnection, dailybudgetItems); services.AddSingleton <IHostedService>(new EventStoreService(esConnection, subscription)); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddOpenApiDocument(settings => { settings.Title = "Budgee"; settings.DocumentName = "v1"; settings.Version = "v1"; }); //services.AddSwaggerGen(c => // c.SwaggerDoc("v1", // new Microsoft.OpenApi.Models.OpenApiInfo { Title = "DailyBudgets", Version = "v1" })); }
public void ConfigureServices(IServiceCollection services) { string executingAssemblyName = Assembly.GetExecutingAssembly().GetName().Name; var esConnection = EventStoreConnection.Create( Configuration["eventStore:connectionString"], ConnectionSettings.Create().KeepReconnecting(), executingAssemblyName); var store = new EsAggregateStore(esConnection); services.AddSingleton(esConnection); services.AddSingleton(store); services.AddSingleton(new SkiPassService(store, new FixedSkiPassLookupService())); services.AddSingleton <IHostedService, HostedService>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "ES SkiPass API", Version = "v1" }); }); services.AddControllers(); services.AddMvc(); }
public async Task read_snapshot_when_loading_aggregate() { var now = DateTime.UtcNow; var esStore = new EsEventStore(GetEventStoreClient(), "snapshot_test"); var esAggregateStore = new EsAggregateStore(esStore, 5); var aggregate = new Day(); var slots = new List <ScheduledSlot> { new ScheduledSlot(TimeSpan.FromMinutes(10), now), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(10)), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(20)), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(30)), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(40)) }; aggregate.Schedule(new DoctorId(Guid.NewGuid()), DateTime.UtcNow, slots, Guid.NewGuid); await esAggregateStore.Save(aggregate, new CommandMetadata(new CorrelationId(Guid.NewGuid()), new CausationId(Guid.NewGuid()))); await esStore.TruncateStream(StreamName.For <Day>(aggregate.Id), Convert.ToUInt64(aggregate.GetChanges().Count())); var reloadedAggregate = await esAggregateStore.Load <Day>(aggregate.Id); Assert.Equal(5, reloadedAggregate.Version); }
public async Task write_snapshot_if_threshold_reached() { var now = DateTime.UtcNow; var esStore = new EsEventStore(GetEventStoreClient(), "snapshot_test"); var esAggregateStore = new EsAggregateStore(esStore, 5); var aggregate = new Day(); var slots = new List <ScheduledSlot> { new ScheduledSlot(TimeSpan.FromMinutes(10), now), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(10)), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(20)), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(30)), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(40)) }; aggregate.Schedule(new DoctorId(Guid.NewGuid()), DateTime.UtcNow, slots, Guid.NewGuid); await esAggregateStore.Save(aggregate, new CommandMetadata(new CorrelationId(Guid.NewGuid()), new CausationId(Guid.NewGuid()))); var snapshotEnvelope = await esStore.LoadSnapshot(StreamName.For <Day>(aggregate.Id)); var snapshot = snapshotEnvelope?.Snapshot as DaySnapshot; Assert.NotNull(snapshot); }
public void ConfigureServices(IServiceCollection services) { var esConnection = EventStoreConnection.Create( Configuration["eventStore:connectionString"], ConnectionSettings.Create().KeepReconnecting(), Environment.ApplicationName); var store = new EsAggregateStore(esConnection); var purgomalumClient = new PurgomalumClient(); var documentStore = ConfigureRavenDb(Configuration.GetSection("ravenDb")); // ReSharper disable once ConvertToLocalFunction Func <IAsyncDocumentSession> getSession = () => documentStore.OpenAsyncSession(); services.AddTransient(c => getSession()); services.AddSingleton(esConnection); services.AddSingleton <IAggregateStore>(store); services.AddSingleton(new ClassifiedAdsApplicationService( store, new FixedCurrencyLookup())); services.AddSingleton(new UserProfileApplicationService( store, t => purgomalumClient.CheckForProfanity(t))); // NOTE: "projection" describes process: // // some event happened -> update read model(s) // // All events are persisted to EventStore. // Read models are persisted to RavenDb. var projectionManager = new ProjectionManager(esConnection, new RavenDbCheckpointStore(getSession, "readmodels"), new ClassifiedAdDetailsProjection(getSession, async userId => (await getSession.GetUserDetails(userId))?.DisplayName), new ClassifiedAdUpcasters(esConnection, async userId => (await getSession.GetUserDetails(userId))?.PhotoUrl), new UserDetailsProjection(getSession)); services.AddSingleton <IHostedService>(new EventStoreService(esConnection, projectionManager)); services.AddMvc(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "ClassifiedAds", Version = "v1" }); }); }
public void ConfigureServices(IServiceCollection services) { var esConnection = EventStoreConnection.Create( Configuration["eventStore:connectionString"], ConnectionSettings.Create().KeepReconnecting(), Environment.ApplicationName); var store = new EsAggregateStore(esConnection); var purgomalumClient = new PurgomalumClient(); services.AddSingleton(esConnection); services.AddSingleton <IAggregateStore>(store); services.AddSingleton(new ClassifiedAdsApplicationService( store, new FixedCurrencyLookup())); services.AddSingleton(new UserProfileApplicationService( store, t => purgomalumClient.CheckForProfanity(t))); var classifiedAdDetails = new List <ReadModels.ClassifiedAdDetails>(); services.AddSingleton <IEnumerable <ReadModels.ClassifiedAdDetails> >(classifiedAdDetails); var userDetails = new List <ReadModels.UserDetails>(); services.AddSingleton <IEnumerable <ReadModels.UserDetails> >(userDetails); var projectionManager = new ProjectionManager(esConnection, new ClassifiedAdDetailsProjection(classifiedAdDetails, userId => userDetails.FirstOrDefault(x => x.UserId == userId)?.DisplayName), new UserDetailsProjection(userDetails), new ClassifiedAdUpcasters(esConnection, userId => userDetails.FirstOrDefault(x => x.UserId == userId)?.PhotoUrl)); services.AddSingleton <IHostedService>( new EventStoreService(esConnection, projectionManager)); services .AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "ClassifiedAds", Version = "v1" }); }); }
// 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) { var adsDetailsItems = new List <ReadModels.PublicClassifiedAdDetails>(); var userDetailsItems = new List <ReadModels.UserDetails>(); services.AddSingleton <IEnumerable <ReadModels.PublicClassifiedAdDetails> >(adsDetailsItems); services.AddSingleton <IEnumerable <ReadModels.UserDetails> >(userDetailsItems); var purgomalumClient = new PurgomalumClient(); //------------EventStore settings var esConnection = EventStoreConnection.Create(Configuration["eventstore:connectionString"], ConnectionSettings.Create().KeepReconnecting(), Environment.ApplicationName); var esStore = new EsAggregateStore(esConnection); var documentStore = ConfigureRavenDb(Configuration.GetSection("ravenDb")); Func <IAsyncDocumentSession> getSession = () => documentStore.OpenAsyncSession(); services.AddTransient(c => getSession()); services.AddSingleton(esConnection); services.AddSingleton <IAggregateStore>(esStore); services.AddSingleton(new ClassifiedAdsApplicationService(esStore, new FixedCurrencyLookup())); services.AddSingleton( new UserProfileApplicationService(esStore, t => purgomalumClient.CheckForProfanity(t))); var subscription = new ProjectionManager(esConnection, new RavenDbCheckpointStore(getSession, "readModels"), new ClassifiedAdDetailsProjection(getSession, async id => ((await getSession.GetUserDetails(id))?.DisplayName)), new UserDetailsProjection(getSession)); services.AddSingleton <IHostedService>(new EventStoreService(esConnection, subscription)); services.AddMvc(); services.AddSwaggerGen(c => c.SwaggerDoc( name: "v1", info: new Info { Title = "ClassifiedAds", Version = "v1" })); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var esConnection = EventStoreConnection.Create( Configuration["eventStore:connectionString"], ConnectionSettings.Create().KeepReconnecting(), Environment.ApplicationName); var store = new EsAggregateStore(esConnection); services.AddSingleton(esConnection); services.AddSingleton <IAggregateStore>(store); services.AddSingleton(new ResourceApplicationService(store)); var resourceDetails = new List <ReadModels.ResourceDetails>(); services.AddSingleton <IEnumerable <ReadModels.ResourceDetails> >(resourceDetails); var projectionManager = new ProjectionManager(esConnection, new ResourceDetailsProjection(resourceDetails), new ResourceUpcasters(esConnection)); services.AddSingleton <IHostedService>( new EventStoreService(esConnection, projectionManager)); services.AddMvc(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Master data service", Version = "v1" }); }); }
public SkiPassService(EsAggregateStore store, FixedSkiPassLookupService fixedSkiPassLookupService) { _store = store; _fixedSkiPassLookupService = fixedSkiPassLookupService; }
public void ConfigureServices(IServiceCollection services) { EventMappings.MapEventTypes(); Modules.UserProfile.EventMappings.MapEventTypes(); var esConnection = EventStoreConnection.Create( Configuration["eventStore:connectionString"], ConnectionSettings.Create().KeepReconnecting(), Environment.ApplicationName ); var store = new EsAggregateStore(esConnection); var purgomalumClient = new PurgomalumClient(); var documentStore = ConfigureRavenDb( Configuration["ravenDb:server"], Configuration["ravenDb:database"] ); Func <IAsyncDocumentSession> getSession = () => documentStore.OpenAsyncSession(); services.AddSingleton( new ClassifiedAdsCommandService(store, new FixedCurrencyLookup()) ); services.AddSingleton( new UserProfileCommandService(store, t => purgomalumClient.CheckForProfanity(t)) ); var ravenDbProjectionManager = new ProjectionManager( esConnection, new RavenDbCheckpointStore(getSession, "readmodels"), ConfigureRavenDbProjections(getSession) ); var upcasterProjectionManager = new ProjectionManager( esConnection, new EsCheckpointStore(esConnection, "upcaster"), ConfigureUpcasters(esConnection, getSession) ); services.AddSingleton(c => getSession); services.AddSingleton(c => new AuthService(getSession)); services.AddScoped(c => getSession()); services.AddSingleton <IHostedService>( new EventStoreService( esConnection, ravenDbProjectionManager, upcasterProjectionManager ) ); services .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(); services .AddMvcCore() .AddJsonFormatters() .AddApiExplorer() .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddSpaStaticFiles( configuration => configuration.RootPath = "ClientApp/dist" ); services.AddSwaggerGen( c => c.SwaggerDoc( "v1", new Info { Title = "ClassifiedAds", Version = "v1" } ) ); }