示例#1
0
        public void Initialize()
        {
            ServiceProvider.MessageBuilder   = new MessageBuilder();
            ServiceProvider.MainMenuFactory  = new MainMenuListFactory();
            ServiceProvider.CurrencyProvider = new DefaultCurrencyProvider();

            StorageFactory storageFactory = new StorageFactory();

            ServiceProvider.EventSourcingContextFactory = storageFactory;
            ServiceProvider.ReadModelContextFactory     = storageFactory;
            ServiceProvider.StorageContainerFactory     = storageFactory;

            Domain();

            PriceCalculator priceCalculator = new PriceCalculator(eventDispatcher.Handlers);

            ServiceProvider.PriceConverter = priceCalculator;

            ReadModels();

            ServiceProvider.QueryDispatcher   = new UserQueryDispatcher(queryDispatcher, () => UserKey);
            ServiceProvider.CommandDispatcher = new UserCommandDispatcher(commandDispatcher, () => UserKey);
            ServiceProvider.EventHandlers     = eventDispatcher.Handlers;

            UpgradeService upgradeService = new UpgradeService(ServiceProvider.CommandDispatcher, EventStore, EventFormatter, storageFactory, storageFactory, storageFactory, priceCalculator, () => UserKey);

            ServiceProvider.UpgradeService = upgradeService;

            ServiceProvider.TileService      = new TileService();
            ServiceProvider.DevelopmentTools = new DevelopmentService(upgradeService, storageFactory);
            ServiceProvider.RestartService   = new RestartService(launchArguments);
            ServiceProvider.AppDataService   = new AppDataService(storageFactory, upgradeService);
            ServiceProvider.UserPreferences  = new ApplicationSettingsService(new CompositeTypeFormatterFactory(typeProvider), storageFactory);

            CurrencyCache currencyCache = new CurrencyCache(eventDispatcher.Handlers, queryDispatcher);

            using (var eventSourcing = ServiceProvider.EventSourcingContextFactory.Create())
                eventSourcing.Database.EnsureCreated();

            using (var readModels = ServiceProvider.ReadModelContextFactory.Create())
                readModels.Database.EnsureCreated();

            if (ServiceProvider.UpgradeService.IsRequired())
            {
                ServiceProvider.UpgradeService.Completed += async() =>
                {
                    Task delay           = Task.Delay(5000);
                    Task currencyCreated = eventDispatcher.Handlers.Await <CurrencyCreated>();

                    await Task.WhenAny(delay, currencyCreated);

                    await Task.Delay(1000);
                    await InitializeCacheAsync(priceCalculator, currencyCache);
                };
            }
            else
            {
                _ = InitializeCacheAsync(priceCalculator, currencyCache);
            }
        }
示例#2
0
        public void Initialize()
        {
            ServiceProvider.MessageBuilder   = new MessageBuilder();
            ServiceProvider.MainMenuFactory  = new MainMenuListFactory();
            ServiceProvider.CurrencyProvider = new DefaultCurrencyProvider();

            StorageFactory storageFactory = new StorageFactory();

            ServiceProvider.EventSourcingContextFactory = storageFactory;
            ServiceProvider.ReadModelContextFactory     = storageFactory;
            ServiceProvider.StorageContainerFactory     = storageFactory;

            Domain();

            PriceCalculator priceCalculator = new PriceCalculator(eventDispatcher.Handlers);

            ServiceProvider.PriceConverter = priceCalculator;

            ReadModels();

            ServiceProvider.QueryDispatcher   = new UserQueryDispatcher(queryDispatcher, () => UserKey);
            ServiceProvider.CommandDispatcher = new UserCommandDispatcher(commandDispatcher, () => UserKey);
            ServiceProvider.EventHandlers     = eventDispatcher.Handlers;

            UpgradeService upgradeService = new UpgradeService(ServiceProvider.CommandDispatcher, EventStore, EventFormatter, storageFactory, storageFactory, storageFactory, priceCalculator, () => UserKey);

            ServiceProvider.UpgradeService = upgradeService;

            ServiceProvider.TileService      = new TileService();
            ServiceProvider.DevelopmentTools = new DevelopmentService(upgradeService, storageFactory);
            ServiceProvider.RestartService   = new RestartService(launchArguments);
            ServiceProvider.UserPreferences  = new ApplicationSettingsService(new CompositeTypeFormatterFactory(typeProvider), storageFactory);

            CurrencyCache currencyCache = new CurrencyCache(eventDispatcher.Handlers, queryDispatcher);

            using (var eventSourcing = ServiceProvider.EventSourcingContextFactory.Create())
                eventSourcing.Database.EnsureCreated();

            using (var readModels = ServiceProvider.ReadModelContextFactory.Create())
                readModels.Database.EnsureCreated();

            currencyCache.InitializeAsync(ServiceProvider.QueryDispatcher);
            priceCalculator.InitializeAsync(ServiceProvider.QueryDispatcher);
        }
示例#3
0
 internal DevelopmentService(UpgradeService upgradeService, StorageFactory storageFactory)
 {
     this.upgradeService = upgradeService;
     this.storageFactory = storageFactory;
 }