Example #1
0
        private static void ConfigureClient()
        {
            var builder = new CqrsClientBuilder();

            builder.File(f => f.AddFileSender(storageConfig, "commands"));

            builder.Domain(d => d.InAssemblyOf<CreateInventoryItem>());

            builder.Storage(s =>
            {
                s.AtomicIsInFiles(storageConfig.Folder.FullName, b =>
                {
                    b.WhereEntityIs<IEntity>();
                    b.WhereSingletonIs<ISingleton>();
                });
                s.StreamingIsInFiles(storageConfig.Folder.FullName);
            });

            builder.Advanced.ConfigureContainer(c=> c.RegisterType<ReadModelFacade>().As<IReadModelFacade>());

            var client = builder.Build();

            ServiceLocator.Bus = client.Resolve<IMessageSender>();
            ServiceLocator.ReadModel = client.Resolve<IReadModelFacade>();
        }
        public static void Azure(this CqrsClientBuilder @this, Action <AzureClientModule> config)
        {
            var module = new AzureClientModule();

            config(module);
            @this.Advanced.RegisterModule(module);
        }
        private static void Main()
        {
            CloudStorageAccount account = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
            IAzureStorageConfig storageConfig = AzureStorage.CreateConfig(account);

            var builder = new CqrsClientBuilder();

            builder.UseProtoBufSerialization();
            builder.Domain(m => m.InAssemblyOf<MessageCreated>());

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

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

            builder.Advanced.ConfigureContainer(b =>
            {
                b.RegisterType<Program>().As<Program>();
                b.RegisterInstance(storageConfig).As<IAzureStorageConfig>();

                //This is solely to show the replaying of events. You wouldn't ordinarily need the eventstore in a cqrs client;
                b.RegisterInstance(ConfigureEventStore()).SingleInstance().As<IStoreEvents>();
            });

            CqrsClient cqrsClient = builder.Build();

            ILifetimeScope scope = cqrsClient.Scope;
            scope.Resolve<Program>().Run();
        }
Example #4
0
        private static void Main()
        {
            CloudStorageAccount account       = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
            IAzureStorageConfig storageConfig = AzureStorage.CreateConfig(account);

            var builder = new CqrsClientBuilder();

            builder.UseProtoBufSerialization();
            builder.Domain(m => m.InAssemblyOf <MessageCreated>());

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

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

            builder.Advanced.ConfigureContainer(b =>
            {
                b.RegisterType <Program>().As <Program>();
                b.RegisterInstance(storageConfig).As <IAzureStorageConfig>();

                //This is solely to show the replaying of events. You wouldn't ordinarily need the eventstore in a cqrs client;
                b.RegisterInstance(ConfigureEventStore()).SingleInstance().As <IStoreEvents>();
            });

            CqrsClient cqrsClient = builder.Build();

            ILifetimeScope scope = cqrsClient.Scope;

            scope.Resolve <Program>().Run();
        }
Example #5
0
        public void Test()
        {
            var dev = AzureStorage.CreateConfigurationForDev();

            WipeAzureAccount.Fast(s => s.StartsWith("test-"), dev);

            var events = new Subject <ISystemEvent>();
            var b      = new CqrsEngineBuilder();

            b.Azure(c => c.AddAzureProcess(dev, "test-publish"));
            b.Advanced.RegisterObserver(events);
            var engine = b.Build();
            var source = new CancellationTokenSource();

            engine.Start(source.Token);



            var builder = new CqrsClientBuilder();

            builder.Azure(c => c.AddAzureSender(dev, "test-publish"));
            var client = builder.Build();


            client.Sender.SendOne(new Message());

            using (engine)
                using (events.OfType <EnvelopeAcked>().Subscribe(e => source.Cancel()))
                {
                    source.Token.WaitHandle.WaitOne(5000);
                    source.Cancel();
                }
        }
 public static void UseProtoBufSerialization(this CqrsClientBuilder self)
 {
     self.Advanced.DataSerializer(t => new DataSerializerWithProtoBuf(t));
     self.Advanced.EnvelopeSerializer(new EnvelopeSerializerWithProtoBuf());
 }