コード例 #1
0
        /// <summary>Registers the type mappings with the Unity container.</summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to
        /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            var baseConfig = EventStoreConfig.GetConfig();

            var promotionsConfig = new DummyEventStoreConfig(DbManager.FixedConnectionstring, baseConfig);
            var user1Config      = new DummyEventStoreConfig(DbManager.FixedConnectionstring, baseConfig);
            var user2Config      = new DummyEventStoreConfig(DbManager.FixedConnectionstring, baseConfig);

            //SingleMicroserviceInitializer.Run(
            //    container, () => MicroserviceFactory<UserManagement, UserManagementHandler>
            //        .CreateEventProcessorWithApp<UserAppService>(container, userConfig),
            //    !_isConsoleApp);

            MultiMicroserviceInitializer.Run(container, () =>
            {
                var services = new List <IMicroservice>();

                UserContainer1 = ContainerFactory.ResolveDependenciesForNewChildContainer(container);
                services.Add(MicroserviceFactory <UserManagement, UserManagementHandler>
                             .CreateEventProcessorWithApp <UserAppService>("user1", "user1_app", UserContainer1, user1Config, plugin,
                                                                           SetupInMemoryPersistence <UserManagement>));

                UserContainer2 = ContainerFactory.ResolveDependenciesForNewChildContainer(container);
                services.Add(MicroserviceFactory <UserManagement, UserManagementHandler>
                             .CreateEventProcessorWithApp <UserAppService>("user2", "user2_app", UserContainer2, user2Config, plugin,
                                                                           SetupInMemoryPersistence <UserManagement>));

                PromotionsContainer = ContainerFactory.ResolveDependenciesForNewChildContainer(container);
                services.Add(MicroserviceFactory <Promotions, PromotionsHandler> .
                             CreateEventProcessor("promo", PromotionsContainer, promotionsConfig, plugin,
                                                  SetupInMemoryPersistence <Promotions>));

                return(services);
            }, false, Program.VerboseIsEnabled);
        }
コード例 #2
0
 public MongoEventStore(IMongoClient mongoClient, EventStoreConfig eventStoreConfig)
 {
     _mongoClient = mongoClient;
     _db          = _mongoClient.GetDatabase("DomainEvents");
     _collection  = _db.GetCollection <Event>("Events");
     _config      = eventStoreConfig;
 }
コード例 #3
0
        /// <summary>Registers the type mappings with the Unity container.</summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to
        /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            var baseConfig = EventStoreConfig.GetConfig();

            var promotionsConfig = new DummyEventStoreConfig(DbManager.FixedConnectionstring, baseConfig);
            var user1Config      = new DummyEventStoreConfig(DbManager.FixedConnectionstring, baseConfig);
            var user2Config      = new DummyEventStoreConfig(DbManager.FixedConnectionstring, baseConfig);

            StatsMonitor = new StatsMonitor();

            EventSystem.Create(
                MicroserviceFactory <UserManagement, UserManagementHandler>
                .CreateEventProcessor("user1", user1Config, null, plugin, persistIncomingEvents, false,
                                      SetupInMemoryPersistence <UserManagement>),

                MicroserviceFactory <UserManagement, UserManagementHandler>
                .CreateEventProcessor("user2", user2Config, null, plugin, persistIncomingEvents, false,
                                      SetupInMemoryPersistence <UserManagement>),

                MicroserviceFactory <Promotions, PromotionsHandler> .
                CreateEventProcessor("promo", promotionsConfig, null, plugin, persistIncomingEvents, false,
                                     SetupInMemoryPersistence <Promotions>,
                                     (consumer, serializer, payload) =>
            {
                var e = serializer.Deserialize <IEvent>(payload);
                if (e is FreePointsRewardedToUser)
                {
                    return(false);
                }
                return(true);
            }));
        }
コード例 #4
0
ファイル: Startup.cs プロジェクト: doliashvili/TestProjectDDD
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSwaggerGenNewtonsoftSupport();
            services.AddSwaggerGen(o =>
            {
                var appXmlName = AppDomain.CurrentDomain.FriendlyName + ".xml";
                var xmlPath    = Path.Combine(AppContext.BaseDirectory, appXmlName);
                o.IncludeXmlComments(xmlPath);
            });

            var rabbitConfig = new RabbitMqConfig()
            {
                UserName    = "******",
                Password    = "******",
                Host        = "localhost",
                Port        = 5672,
                VirtualHost = "/",
                Exchange    = "test"
            };

            services.AddSingleton(rabbitConfig);
            services.AddSingleton <IRabbitConnectionWrapper, RabbitConnectionWrapper>();
            services.AddRabbitMq(typeof(AppleCreatedEventHandler).Assembly);

            services.AddCommandHandlers(typeof(AppleCommandHandlers).Assembly);
            services.AddInternalEventHandlers(typeof(AppleCommandHandlers).Assembly,
                                              typeof(AppleReadModel).Assembly);
            services.AddInternalEventPublisher();
            services.AddCommandSender();

            var eventStoreConfig = new EventStoreConfig();

            Configuration.GetSection(nameof(EventStoreConfig)).Bind(eventStoreConfig);
            var mongoConfig = new MongoConfig();

            Configuration.GetSection(nameof(MongoConfig)).Bind(mongoConfig);

            services.AddSingleton <IEventProducer, RabbitMqProducer>();
            services.AddEventStoreConfig(eventStoreConfig);
            services.AddMongoDb(mongoConfig);
            services.ConfigureMongoEventStore();
            services.ConfigureRepositories();

            var ravenSettings = new RavenSettings();

            Configuration.GetSection(nameof(RavenSettings)).Bind(ravenSettings);
            services.AddSingleton(ravenSettings);
            services.AddRavenDb(ravenSettings);
            services.AddQueryHandlers(typeof(AppleReadModel).Assembly);
            services.AddQueryProcessor();

            services
            .AddTransient <IReadModelRepository <AppleReadModel, string>,
                           RavenReadModelRepository <AppleReadModel, string> >();

            services.AddControllers().AddNewtonsoftJson(o =>
            {
                o.SerializerSettings.ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor;
            });
        }
コード例 #5
0
 internal static IEventStoreConfig ResolveConfig(IEventStoreConfig providedConfig)
 {
     try
     {
         return(providedConfig != null ? providedConfig : EventStoreConfig.GetConfig());
     }
     catch (ArgumentNullException)
     {
         return(new HardcodedEventStoreConfig());
     }
 }
コード例 #6
0
        static EquinoxContext ConfigureStore()
        {
#if (cosmos || eventStore)
            // This is the allocation limit passed internally to a System.Caching.MemoryCache instance
            // The primary objects held in the cache are the Folded State of Event-sourced aggregates
            // see https://docs.microsoft.com/en-us/dotnet/framework/performance/caching-in-net-framework-applications for more information
            var cacheMb = 50;
#endif
#if eventStore
            // EVENTSTORE: see https://eventstore.org/
            // Requires a Commercial HA Cluster, which can be simulated by 1) installing the OSS Edition from Choocolatey 2) running it in cluster mode

            // # requires admin privilege
            // cinst eventstore-oss -y # where cinst is an invocation of the Chocolatey Package Installer on Windows
            // # run as a single-node cluster to allow connection logic to use cluster mode as for a commercial cluster
            // & $env:ProgramData\chocolatey\bin\EventStore.ClusterNode.exe --gossip-on-single-node --discover-via-dns 0 --ext-http-port=30778

            var esConfig = new EventStoreConfig("localhost", "admin", "changeit", cacheMb);
            return(new EventStoreContext(esConfig));
#endif
#if cosmos
            // AZURE COSMOSDB: Events are stored in an Azure CosmosDb Account (using the SQL API)
            // Provisioning Steps:
            // 1) Set the 3x environment variables EQUINOX_COSMOS_CONNECTION, EQUINOX_COSMOS_DATABASE, EQUINOX_COSMOS_COLLECTION
            // 2) Provision a collection using the following command sequence:
            //     dotnet tool install -g Equinox.Cli
            //     Equinox.Cli init -ru 1000 cosmos -s $env:EQUINOX_COSMOS_CONNECTION -d $env:EQUINOX_COSMOS_DATABASE -c $env:EQUINOX_COSMOS_COLLECTION
            const string connVar = "EQUINOX_COSMOS_CONNECTION";
            var          conn    = Environment.GetEnvironmentVariable(connVar);
            const string dbVar   = "EQUINOX_COSMOS_DATABASE";
            var          db      = Environment.GetEnvironmentVariable(dbVar);
            const string collVar = "EQUINOX_COSMOS_COLLECTION";
            var          coll    = Environment.GetEnvironmentVariable(collVar);
            if (conn == null || db == null || coll == null)
            {
                throw new Exception(
                          $"Event Storage subsystem requires the following Environment Variables to be specified: {connVar} {dbVar}, {collVar}");
            }
            var connMode = Equinox.Cosmos.ConnectionMode.DirectTcp;
            var config   = new CosmosConfig(connMode, conn, db, coll, cacheMb);
            return(new CosmosContext(config));
#endif
#if (!cosmos && !eventStore)
            return(new MemoryStoreContext(new Equinox.MemoryStore.VolatileStore()));
#endif
#if (!memoryStore && !cosmos && !eventStore)
            //return new MemoryStoreContext(new Equinox.MemoryStore.VolatileStore());
#endif
        }
コード例 #7
0
        /// <inheritdoc/>
        public void Provide(IBindingProviderBuilder builder)
        {
            var mongoConnectionString = Environment.GetEnvironmentVariable("MONGO");
            var client           = new MongoClient(mongoConnectionString);
            var database         = client.GetDatabase("CI_EventStore");
            var eventStoreConfig = new EventStoreConfig(database, Dolittle.Logging.Logger.Internal);

            builder.Bind <EventStoreConfig>().To(eventStoreConfig);

            builder.Bind <IEventStore>().To <Dolittle.Runtime.Events.Store.MongoDB.EventStore>();

            builder.Bind <Dolittle.ReadModels.MongoDB.Configuration>().To(new Dolittle.ReadModels.MongoDB.Configuration
            {
                Url             = mongoConnectionString,
                UseSSL          = false,
                DefaultDatabase = "CI_Read"
            });
            builder.Bind(typeof(IReadModelRepositoryFor <>)).To(typeof(ReadModelRepositoryFor <>));
        }
コード例 #8
0
 public EventStoreConnectionWrapper(EventStoreConfig config)
 {
     Configuration = config;
     Connection    = EventStoreConnection.Create(Configuration.ConnectionString);
     Connection.ConnectAsync().GetAwaiter().GetResult();
 }
コード例 #9
0
 /// <summary>
 /// Add mongoDb implementation of IEventStore
 /// </summary>
 /// <param name="services"></param>
 /// <param name="mongoConfig"></param>
 /// <param name="eventStoreConfig"></param>
 /// <returns></returns>
 public static IServiceCollection AddMongoDbEventStore(this IServiceCollection services,
                                                       MongoConfig mongoConfig, EventStoreConfig eventStoreConfig)
 {
     BsonSerializer.RegisterSerializationProvider(new CustomSerializationProvider());
     services.AddSingleton(mongoConfig)
     .AddSingleton(eventStoreConfig)
     .AddSingleton <IMongoConnectionWrapper, MongoConnectionWrapper>()
     .RegisterStores(false);
     return(services);
 }