Ejemplo n.º 1
0
        // public static method we call on startup to setup our simple console environment and to wire things up
        public static ConsoleEnvironment BuildEnvironment()
        {
            // a little bit of our simple infrastructure in here
            // this infrastructure binds our simple in-memory EventStore and multiple Projections to each other

            // E17 added the SynchronousEventHandler class to keep event handling simple without queues for now
            // this handler is now passed to our in-memory eventStore
            var eventHandlers = new SynchronousEventHandler();
            var eventStore = new InMemoryStore(eventHandlers);

            var blueprints = new InMemoryBlueprintLibrary();
            blueprints.Register("model-t", new CarPart("wheel",4), new CarPart("engine",1), new CarPart("chassis",1));

            // In non-demo environments we usually want Application Services decoupled from Projections
            // but we will not worry about that now for this simple example

            // Application Service (Command message handler)
            // get app service ready to respond to Command messages
            var factoryAppSvc = new FactoryApplicationService(eventStore, blueprints);

            // Projections (Event message handlers)
            // directly wire projections to the Event Handlers for now
            // (not using production-like queues to store the Events in for this simple example)

            // projections can also be thought of as almost another kind of Application Service
            // Application Services and Projections BOTH handle Messages, but
            // Projections just happen to subscribe & respond to "When..." Event messages ("eventHandlers"),
            // instead of "When..." Command messages

            var activeFactories = new ActiveFactoriesProjection();
            eventHandlers.RegisterHandler(activeFactories);

            var workerRegistry = new WorkerRegistryProjection();
            eventHandlers.RegisterHandler(workerRegistry);

            var inventory = new InventoryProjection();
            eventHandlers.RegisterHandler(inventory);

            return new ConsoleEnvironment
                {
                    Events = eventStore,
                    FactoryAppService = factoryAppSvc,
                    ActionHandlers = ConsoleActions.Actions,
                    Blueprints = blueprints,
                    ActiveFactories = activeFactories,
                    WorkerRegistry = workerRegistry,
                    Inventory = inventory
                };
        }
Ejemplo n.º 2
0
        // public static method we call on startup to setup our simple console environment and to wire things up
        public static ConsoleEnvironment BuildEnvironment()
        {
            // a little bit of our simple infrastructure in here
            // this infrastructure binds our simple in-memory EventStore and multiple Projections to each other

            // E17 added the SynchronousEventHandler class to keep event handling simple without queues for now
            // this handler is now passed to our in-memory eventStore
            var eventHandlers = new SynchronousEventHandler();
            var eventStore = new InMemoryStore(eventHandlers);
            
            var blueprints = new InMemoryBlueprintLibrary();
            blueprints.Register("model-t", new CarPart("wheel",4), new CarPart("engine",1), new CarPart("chassis",1));

            // In non-demo environments we usually want Application Services decoupled from Projections
            // but we will not worry about that now for this simple example

            // Application Service (Command message handler)
            // get app service ready to respond to Command messages
            var factoryAppSvc = new FactoryApplicationService(eventStore, blueprints);


            // Projections (Event message handlers)
            // directly wire projections to the Event Handlers for now
            // (not using production-like queues to store the Events in for this simple example)

            // projections can also be thought of as almost another kind of Application Service
            // Application Services and Projections BOTH handle Messages, but
            // Projections just happen to subscribe & respond to "When..." Event messages ("eventHandlers"),
            // instead of "When..." Command messages

            var activeFactories = new ActiveFactoriesProjection();
            eventHandlers.RegisterHandler(activeFactories);

            var workerRegistry = new WorkerRegistryProjection();
            eventHandlers.RegisterHandler(workerRegistry);

            var inventory = new InventoryProjection();
            eventHandlers.RegisterHandler(inventory);

            // setup Window size values for Console Window that is 60% of Max Possible Size
            int winWidth = (System.Console.LargestWindowWidth * 6 / 10);
            int winHeight = (System.Console.LargestWindowHeight * 6 / 10);

            // hack - for now, hard code "bigger" buffer than Window sizes above
            // keep horizontal buffer equal to width - to avoid horizontal scrolling
            int winBuffWidth = winWidth;
            int winBuffHeight = winHeight + 300;
            System.Console.SetBufferSize(winBuffWidth, winBuffHeight);

            // Buffer is bigger than Window so set the Window Size
            System.Console.SetWindowSize(winWidth, winHeight);

            // note that various tricks to center Console Window on launch 
            // and to change to Font size were ugly (PInvoke, etc.) so left them out for now

            System.Console.Title = "Being The Worst Interactive Factory Shell";


            return new ConsoleEnvironment
                {
                    Events = eventStore,
                    FactoryAppService = factoryAppSvc,
                    ActionHandlers = ConsoleActions.Actions,
                    Blueprints = blueprints,
                    ActiveFactories = activeFactories,
                    WorkerRegistry = workerRegistry,
                    Inventory = inventory
                };
        }