예제 #1
0
 public void Dispose()
 {
     if (runtime != null)
     {
         runtime.Dispose();
         runtime = null;
     }
 }
예제 #2
0
        static void Main(string[] args)
        {
            var runtime = new SampleRunTime();

            runtime.Start();

            // Infrastructure and fakes
            var fakeAccountTable = new FakeAccountTable();

            runtime.ServiceLocator.Register(fakeAccountTable); // Create Fake-db
            runtime.ServiceLocator.Register(new AccountReportReadService(fakeAccountTable));
            var commandBus = runtime.ServiceLocator.Resolve <ICommandBus>();


            // Create and send a couple of command
            var cmdMarcus = new CreateAccountCommand {
                FirstName = "Marcus", LastName = "Hammarberg"
            };
            var cmdDarren = new CreateAccountCommand {
                FirstName = "Darren", LastName = "Cauthon"
            };
            var cmdTyrone = new CreateAccountCommand {
                FirstName = "Tyrone", LastName = "Groves"
            };

            commandBus.Send(cmdMarcus);
            commandBus.Send(cmdDarren);
            commandBus.Send(cmdTyrone);

            // Get the denormalized version of the data back from the read model
            var accountReportReadModel = runtime.ServiceLocator.Resolve <AccountReportReadService>();

            Console.WriteLine("Accounts in database");
            Console.WriteLine("####################");
            foreach (var account in accountReportReadModel.GetAccounts())
            {
                Console.WriteLine(" Id: {0} Name: {1}", account.Id, account.Name);
            }



            runtime.Shutdown();

            Console.ReadLine();
        }
예제 #3
0
        private void Run()
        {
            runtime = new SampleRunTime(CONNECTION_STRING);
            runtime.Start();

            // Configure dependencies
            System.Data.Entity.Database.SetInitializer <SqlBankContext>(new System.Data.Entity.DropCreateDatabaseIfModelChanges <SqlBankContext>());
            var db = new SqlBankContext(CONNECTION_STRING);

            runtime.ServiceLocator.Register(db);

            // Get the Command Bus
            commandBus = runtime.ServiceLocator.Resolve <ICommandBus>();
            // Create and send a couple of command
            var accountReportReadModel = runtime.ServiceLocator.Resolve <AccountReportReadService>();
            var accounts = accountReportReadModel.GetAccounts();

            if (accounts.Count() == 0)
            {
                Console.WriteLine("Adding initial data...\n\n\n");
                var cmdMarcus = new CreateAccountCommand {
                    FirstName = "Marcus", LastName = "Hammarberg"
                };
                var cmdDarren = new CreateAccountCommand {
                    FirstName = "Darren", LastName = "Cauthon"
                };
                var cmdTyrone = new CreateAccountCommand {
                    FirstName = "Tyrone", LastName = "Groves"
                };
                commandBus.Send(cmdMarcus);
                commandBus.Send(cmdDarren);
                commandBus.Send(cmdTyrone);
            }

            ProcessMenu();

            runtime.Shutdown();

            Console.ReadLine();
        }