예제 #1
0
        protected override CqrsEngineHost BuildHost()
        {
            var builder = new CqrsEngineBuilder();

            //NOTE: Core Lokad CQRS Initialization
            builder.UseProtoBufSerialization();

            builder.Domain(config =>
            {
                config.InAssemblyOf <CreateMessage>();
                config.InAssemblyOf <CreateMessageHandler>();
                config.ContextFactory(MyMessageContext.Factory);
            });

            var storageConfig = CreateCloudStorageConfig();

            builder.Azure(config =>
            {
                config.AddAzureProcess(storageConfig, Queues.MESSAGES);
                config.AddAzureSender(storageConfig, Queues.MESSAGES);
            });

            builder.Storage(config => config.AtomicIsInAzure(storageConfig, s =>
            {
                s.WithAssemblyOf <MessageView>();
                s.CustomStaticSerializer(new AtomicStorageSerializerWithProtoBuf());
            }));

            //NOTE: Event Store Initialization
            builder.ConfigureJonathanOliverEventStore(config =>
            {
                var connectionString = AzureSettingsProvider.GetString("EventStoreConnectionString");

                config.ConnectionString(connectionString);
                config.Hooks(p => p.Add <MyNullPipelineHook>());
                config.Snapshots(s =>
                {
                    //snapshotting isn't implemented correctly right now.
                    s.Disable();
                    s.CheckEvery(TimeSpan.FromSeconds(30));
                    //set this to something reasonable like 250.
                    //It's so low here to demonstrate background "out-of-band" snapshotting.
                    s.MaxThreshold(2);
                });
            });

            return(builder.Build());
        }
        protected override CqrsEngineHost BuildHost()
        {
            var builder = new CqrsEngineBuilder();

            //NOTE: Core Lokad CQRS Initialization
            builder.UseProtoBufSerialization();

            builder.Domain(config =>
            {
                config.InAssemblyOf<CreateMessage>();
                config.InAssemblyOf<CreateMessageHandler>();
                config.ContextFactory(MyMessageContext.Factory);
            });

            var storageConfig = CreateCloudStorageConfig();

            builder.Azure(config =>
            {

                config.AddAzureProcess(storageConfig, Queues.MESSAGES);
                config.AddAzureSender(storageConfig, Queues.MESSAGES);
            });

            builder.Storage(config => config.AtomicIsInAzure(storageConfig, s =>
            {
                s.WithAssemblyOf<MessageView>();
                s.CustomStaticSerializer(new AtomicStorageSerializerWithProtoBuf());
            }));

            //NOTE: Event Store Initialization
            builder.ConfigureJonathanOliverEventStore(config =>
            {
                var connectionString = AzureSettingsProvider.GetString("EventStoreConnectionString");

                config.ConnectionString(connectionString);
                config.Hooks(p => p.Add<MyNullPipelineHook>());
                config.Snapshots(s =>
                {
                    //snapshotting isn't implemented correctly right now.
                    s.Disable();
                    s.CheckEvery(TimeSpan.FromSeconds(30));
                    //set this to something reasonable like 250.
                    //It's so low here to demonstrate background "out-of-band" snapshotting.
                    s.MaxThreshold(2);
                });
            });

            return builder.Build();
        }
        private static CqrsEngineBuilder GetBuilder()
        {
            var builder = new CqrsEngineBuilder();

            //NOTE: Core Lokad CQRS Initialization
            builder.UseProtoBufSerialization();

            builder.Domain(config =>
            {
                config.InAssemblyOf<CreateMessage>();
                config.InAssemblyOf<CreateMessageHandler>();
                config.ContextFactory(MyMessageContext.Factory);
            });

            builder.Memory(config =>
            {
                config.AddMemoryProcess(Queues.MESSAGES, d=>{});
                config.AddMemorySender(Queues.MESSAGES);
            });

            builder.Storage(config =>
            {
                var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "storage");
                if (!Directory.Exists(folder))
                    Directory.CreateDirectory(folder);

                config.AtomicIsInFiles(folder, s =>
                {
                    s.NameForSingleton(type => DefaultAtomicStorageStrategyBuilder.CleanName(type.Name) + ".json");
                    s.NameForEntity((type, key) => (DefaultAtomicStorageStrategyBuilder.CleanName(type.Name) + "-" + Convert.ToString(key, CultureInfo.InvariantCulture).ToLowerInvariant()) + ".json");
                    s.WithAssemblyOf<MessageView>();
                    s.CustomStaticSerializer(new AtomicStorageSerializerWithJson());
                });
                config.StreamingIsInFiles(folder);
            });

            //NOTE: Event Store Initialization
            builder.ConfigureJonathanOliverEventStore(config =>
            {
                const string CONNECTION_STRING = @"Data Source=.\sqlexpress;Initial Catalog=lokad-cqrs-eventstore;Integrated Security=True";

                config.ConnectionString(CONNECTION_STRING);
                config.Hooks(p => p.Add<MyNullPipelineHook>());
                config.Snapshots(s =>
                {
                    s.Enable();
                    s.AggregateTypeResolver(typeName => Type.GetType(typeName + ",Domain"));
                    s.CheckEvery(TimeSpan.FromSeconds(30));
                    //set this to something reasonable like 250.
                    //It's so low here to demonstrate background "out-of-band" snapshotting.
                    s.MaxThreshold(5);
                });
            });

            return builder;
        }