private async Task ConfigureServicesAsync(IServiceCollection services) { var gesConnection = EventStoreConnection.Create( Configuration["EventStore:ConnectionString"], ConnectionSettings.Create().KeepReconnecting(), Environment.ApplicationName); gesConnection.Connected += (sender, args) => Log.Information("Connection to {endpoint} event store established.", args.RemoteEndPoint); await gesConnection.ConnectAsync(); var serializer = new JsonNetSerializer(); var typeMapper = new TypeMapper() .Map <Events.V1.ClassifiedAdCreated>("ClassifiedAdCreated") .Map <Events.V1.ClassifiedAdRenamed>("ClassifiedAdRenamed") .Map <Events.V1.ClassifiedAdPriceChanged>("ClassifiedAdPriceChanged") .Map <Events.V1.ClassifiedAdActivated>("ClassifiedAdActivated") .Map <Events.V1.ClassifiedAdDeactivated>("ClassifiedAdDeactivated") .Map <Events.V1.ClassifiedAdPublished>("ClassifiedAdPublished") .Map <Events.V1.ClassifiedAdMarkedAsSold>("ClassifiedAdMarkedAsSold"); var aggregateStore = new GesAggregateStore( (type, id) => $"{type.Name}-{id}", gesConnection, serializer, typeMapper); services.AddSingleton(new ClassifiedAdsApplicationService(aggregateStore)); var documentStore = ConfigureRaven(services); await ProjectionManagerBuilder.With .Connection(gesConnection) .Serializer(serializer) .TypeMapper(typeMapper) .CheckpointStore(new RavenCheckpointStore(() => documentStore.OpenAsyncSession())) .Projections( new ClassifiedAdsByOwner(() => documentStore.OpenAsyncSession()), new ActiveClassifiedAds(() => documentStore.OpenAsyncSession())) .Activate(); services.AddMvc(); services.AddSwaggerGen(c => { c.IncludeXmlComments($"{CurrentDirectory}/Marketplace.xml"); c.SwaggerDoc( $"v{Configuration["Swagger:Version"]}", new Info { Title = Configuration["Swagger:Title"], Version = $"v{Configuration["Swagger:Version"]}" }); }); }
public async Task can_save_aggregate() { var aggregate = new Reviews.Domain.Review(); aggregate.Apple(AutoFixture.Create <Domain.Events.V1.ReviewCreated>()); aggregate.Apple(AutoFixture.Create <Domain.Events.V1.ReviewApproved>()); var sut = new GesAggregateStore(Connection, null); var result = await sut.Save(aggregate); result.NextExceptedVersion.Should().Be(1); }
private async Task BuildEventStore(IServiceCollection services) { //Create EventStore Connection var eventStoreConnection = EventStoreConnection.Create( Configuration["EventStore:ConnectionString"], ConnectionSettings.Create() .KeepReconnecting() .EnableVerboseLogging() .SetHeartbeatInterval(TimeSpan.FromMilliseconds(5 * 1000)) .UseDebugLogger(), Environment.ApplicationName ); eventStoreConnection.Connected += (sender, args) => Console.WriteLine($"Connection to {args.RemoteEndPoint} event store established."); eventStoreConnection.ErrorOccurred += (sender, args) => Console.WriteLine($"Connection error : {args.Exception}"); await eventStoreConnection.ConnectAsync(); /* * eventStore cluster connection builder * var eventStoreConnection= await EventStoreConnectionBuilder.ConfigureStore(); */ var aggregateStore = new GesAggregateStore(eventStoreConnection, null); var gesSnapshotStore = new GesSnapshotStore(eventStoreConnection, null); var repository = new Repository(aggregateStore, gesSnapshotStore); services.AddSingleton <IRepository>(repository); services.AddSingleton(new ApplicationService(repository)); var documentStore = RavenDbConfiguration.Build(Configuration["RavenDb:Url"], Configuration["RavenDb:Database"]); IDocumentSession GetSession() => documentStore.OpenSession(); await ProjectionManager.With .Connection(eventStoreConnection) .CheckpointStore(new RavenDbCheckPointStore(GetSession)) .SetProjections(new Projection[] { new ActiveReviews(GetSession), new ReviewsByOwner(GetSession), new ReviewsByProducts(GetSession), }) .StartAll(); }
public async Task can_save_aggregate() { var aggregate = new ClassifiedAd(); aggregate.Apply(AutoFixture.Create <Events.V1.ClassifiedAdCreated>()); aggregate.Apply(AutoFixture.Create <Events.V1.ClassifiedAdPublished>()); aggregate.Apply(AutoFixture.Create <Events.V1.ClassifiedAdMarkedAsSold>()); var sut = new GesAggregateStore((type, id) => id, Connection, Serializer, TypeMapper); var result = await sut.Save(aggregate); // act & assert result.NextExpectedVersion.Should().Be(2); }
public async Task can_load_aggregate() { var aggregate = new Reviews.Domain.Review(); aggregate.Apple(AutoFixture.Build <Domain.Events.V1.ReviewCreated>().With(e => e.Id, AggregateId).Create()); aggregate.Apple(AutoFixture.Build <Domain.Events.V1.ReviewApproved>().With(e => e.Id, AggregateId).Create()); var sut = new GesAggregateStore(Connection, null); var saveResult = await sut.Save(aggregate); var result = await sut.Load <Domain.Review>(AggregateId.ToString()); result.Id.Should().Be(AggregateId); }
async Task ConfigureServicesAsync(IServiceCollection services) { var gesConnection = EventStoreConnection.Create( Configuration["EventStore:ConnectionString"], ConnectionSettings.Create().KeepReconnecting(), Environment.ApplicationName); gesConnection.Connected += (sender, args) => Log.Information("Connection to {endpoint} event store established.", args.RemoteEndPoint); await gesConnection.ConnectAsync(); var serializer = new JsonNetSerializer(); var typeMapper = new TypeMapper() .Map <Events.V1.InvestorNameChanged>(nameof(Events.V1.InvestorNameChanged)) .Map <Events.V1.InvestorRegistered>(nameof(Events.V1.InvestorRegistered)) .Map <Events.V1.CompanyRegistered>(nameof(Events.V1.CompanyRegistered)) .Map <Events.V1.InvestorScreeningCriteriaChanged>(nameof(Events.V1.InvestorScreeningCriteriaChanged)) .Map <Events.V1.CompanyScoreChanged>(nameof(Events.V1.CompanyScoreChanged)); var aggregateStore = new GesAggregateStore( (type, id) => $"{type.Name}-{id}", gesConnection, serializer, typeMapper); services.AddSingleton(new InvestorsApplicationService( aggregateStore, () => DateTimeOffset.UtcNow)); var documentStore = ConfigureRaven(); IAsyncDocumentSession GetSession() => documentStore.OpenAsyncSession(); services.AddSingleton <Func <IAsyncDocumentSession> >(GetSession); services.AddSingleton(new InvestorsQueryService(GetSession)); await ProjectionManager.With .Connection(gesConnection) .Serializer(serializer) .TypeMapper(typeMapper) .CheckpointStore(new RavenCheckpointStore(GetSession)) .Projections( new InvestorDashboardProjection(GetSession)) .Activate(); services.AddCors(); services.AddMvc(); services.AddSwaggerGen(c => { c.DescribeAllEnumsAsStrings(); c.DescribeAllParametersInCamelCase(); c.DescribeStringEnumsInCamelCase(); //c.AddSecurityDefinition("Piedpiper", new ApiKeyScheme { In = "header", Description = "Please enter JWT with Bearer into field", Name = "Authorization", Type = "apiKey" }); //c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>> { // { "Bearer", Enumerable.Empty<string>() }, //}); c.SwaggerDoc("v1", new Info { Title = "Piedpiper api", Version = "v1" }); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); }
async Task ConfigureServicesAsync(IServiceCollection services) { var gesConnection = EventStoreConnection.Create( Configuration["EventStore:ConnectionString"], ConnectionSettings.Create().KeepReconnecting(), Environment.ApplicationName); gesConnection.Connected += (sender, args) => Log.Information("Connection to {endpoint} event store established.", args.RemoteEndPoint); await gesConnection.ConnectAsync(); var serializer = new JsonNetSerializer(); var typeMapper = new TypeMapper() .Map <Events.V1.ClassifiedAdRegistered>("Marketplace.V1.ClassifiedAdRegistered") .Map <Events.V1.ClassifiedAdTitleChanged>("Marketplace.V1.ClassifiedAdTitleChanged") .Map <Events.V1.ClassifiedAdTextChanged>("Marketplace.V1.ClassifiedAdTextUpdated") .Map <Events.V1.ClassifiedAdPriceChanged>("Marketplace.V1.ClassifiedAdPriceChanged") .Map <Events.V1.ClassifiedAdPublished>("Marketplace.V1.ClassifiedAdPublished") .Map <Events.V1.ClassifiedAdSold>("Marketplace.V1.ClassifiedAdMarkedAsSold") .Map <Events.V1.ClassifiedAdRemoved>("Marketplace.V1.ClassifiedAdRemoved"); var aggregateStore = new GesAggregateStore( (type, id) => $"{type.Name}-{id}", gesConnection, serializer, typeMapper); var purgomalumClient = new PurgomalumClient(); services.AddSingleton(new ClassifiedAdsApplicationService( aggregateStore, () => DateTimeOffset.UtcNow, text => purgomalumClient.CheckForProfanity(text))); var documentStore = ConfigureRaven(); IAsyncDocumentSession GetSession() => documentStore.OpenAsyncSession(); services.AddSingleton <Func <IAsyncDocumentSession> >(GetSession); services.AddSingleton(new ClassifiedAdsQueryService(GetSession)); await ProjectionManager.With .Connection(gesConnection) .Serializer(serializer) .TypeMapper(typeMapper) .CheckpointStore(new RavenCheckpointStore(GetSession)) .Projections( new SoldClassifiedAdsProjection(GetSession), new AvailableClassifiedAdsProjection(GetSession)) .Activate(); services.AddMvc(); services.AddSwaggerGen(c => { c.IncludeXmlComments($"{CurrentDirectory}/Marketplace.xml"); c.SwaggerDoc( $"v{Configuration["Swagger:Version"]}", new Info { Title = Configuration["Swagger:Title"], Version = $"v{Configuration["Swagger:Version"]}" }); }); }