public void ConfigureServices(IServiceCollection services) { var esConnection = EventStoreConnection.Create( Configuration["eventStore:connectionString"], ConnectionSettings.Create().KeepReconnecting(), Environment.ApplicationName ); var purgomalumClient = new PurgomalumClient(); var documentStore = ConfigureRavenDb( Configuration["ravenDb:server"] ); services.AddSingleton(new ImageQueryService(ImageStorage.GetFile)); services.AddSingleton(esConnection); services.AddSingleton(documentStore); services.AddSingleton <IHostedService, EventStoreService>(); services .AddAuthentication( CookieAuthenticationDefaults.AuthenticationScheme ) .AddCookie(); services .AddMvcCore( options => options.Conventions.Add(new CommandConvention()) ) .AddApplicationPart(GetType().Assembly) .AddAdsModule( "ClassifiedAds", new FixedCurrencyLookup(), ImageStorage.UploadFile ) .AddUsersModule( "Users", purgomalumClient.CheckForProfanity ) .AddPaidServicesModule("PaidServices") .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" } ) ); }
public void ConfigureServices(IServiceCollection services) { const string connectionString = "Host=localhost;Database=Marketplace_Chapter9;Username=ddd;Password=book"; services.AddEntityFrameworkNpgsql(); services.AddPostgresDbContext <MarketplaceDbContext>(connectionString); services.AddScoped <DbConnection>(c => new NpgsqlConnection(connectionString)); var purgomalumClient = new PurgomalumClient(); services.AddSingleton <ICurrencyLookup, FixedCurrencyLookup>(); services.AddScoped <IUnitOfWork, EfCoreUnitOfWork>(); services.AddScoped <IClassifiedAdRepository, ClassifiedAdRepository>(); services.AddScoped <IUserProfileRepository, UserProfileRepository>(); services.AddScoped <ClassifiedAdsApplicationService>(); services.AddScoped(c => new UserProfileApplicationService( c.GetService <IUserProfileRepository>(), c.GetService <IUnitOfWork>(), text => purgomalumClient.CheckForProfanity(text).GetAwaiter().GetResult())); 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))); services.AddSingleton <IHostedService, HostedService>(); 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(); 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) { // const string connectionString = "Host=localhost;Database=Marketplace_Chapter8;Username=ddd;Password=book"; // // services.AddEntityFrameworkNpgsql(); // services.AddPostgresDbContext<MarketPlaceDbContext>(connectionString); // services.AddScoped<DbConnection>(c => new NpgsqlConnection(connectionString)); var store = new DocumentStore { Urls = new[] { "http://localhost:8080/" }, Database = "Marketplace_Chapter9", Conventions = { FindIdentityProperty = m => m.Name == "DbId" } }; store.Initialize(); services.AddScoped(c => store.OpenAsyncSession()); var purgomalumClient = new PurgomalumClient(); services.AddSingleton <ICurrencyLookup, FixedCurrencyLookup>(); services.AddScoped <IUnitOfWork, RavenDbUnitOfWork>(); services.AddScoped <IClassifiedAdRepository, ClassifiedAdRepository>(); services.AddScoped <IUserProfileRepository, UserProfileRepository>(); services.AddScoped <ClassifiedAdsApplicationService>(); services.AddScoped(c => new UserProfileApplicationService(c.GetService <IUserProfileRepository>(), c.GetService <IUnitOfWork>(), text => purgomalumClient.CheckForProfanity(text).GetAwaiter().GetResult())); services.AddMvc(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "ClassifiedAds", Version = "v1" }); }); }
public void ConfigureServices(IServiceCollection services) { var store = new DocumentStore { Urls = new[] { "http://localhost:8080" }, Database = "Marketplace_Chapter9", Conventions = { FindIdentityProperty = x => x.Name == "DbId" } }; store.Initialize(); var purgomalumClient = new PurgomalumClient(); services.AddSingleton <ICurrencyLookup, FixedCurrencyLookup>(); services.AddScoped(c => store.OpenAsyncSession()); services.AddScoped <IUnitOfWork, RavenDbUnitOfWork>(); services.AddScoped <IClassifiedAdRepository, ClassifiedAdRepository>(); services.AddScoped <IUserProfileRepository, UserProfileRepository>(); services.AddScoped <ClassifiedAdsApplicationService>(); services.AddScoped(c => new UserProfileApplicationService( c.GetService <IUserProfileRepository>(), c.GetService <IUnitOfWork>(), text => purgomalumClient.CheckForProfanity(text).GetAwaiter().GetResult())); services.AddMvc(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "ClassifiedAds", Version = "v1" }); }); }
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" } ) ); }
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.ClassifiedAdTextUpdated>("ClassifiedAdTextUpdated") .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); var purgomalumClient = new PurgomalumClient(); services.AddSingleton(new ClassifiedAdsApplicationService( aggregateStore, () => DateTimeOffset.UtcNow, text => purgomalumClient.CheckForProfanity(text))); var documentStore = ConfigureRaven(); IAsyncDocumentSession GetSession() => documentStore.OpenAsyncSession(); await ProjectionManager.With .Connection(gesConnection) .Serializer(serializer) .TypeMapper(typeMapper) .CheckpointStore(new RavenCheckpointStore(GetSession)) .Projections( new ClassifiedAdsByOwner(GetSession), new ActiveClassifiedAds(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"]}" }); }); }