コード例 #1
0
        public void Build(IAppInfo appInfo)
        {
            if (startups == null)
            {
                throw new InvalidOperationException("Cannot build an already build container");
            }

            var serviceRegistry = new ServiceRegistry();

            var appDataManager = new AppDataManager(appInfo);
            var settingManager = new IOSettingsManager(appDataManager);

            serviceRegistry.AddSingleton(appInfo);
            serviceRegistry.AddSingleton <IAppDataManager>(appDataManager);
            serviceRegistry.AddSingletonWithAutoInject <IIOSettingsManager, IOSettingsManager>(settingManager);

            var startupContext = new StartupContext(appInfo, appDataManager, settingManager);

            foreach (var startup in startups)
            {
                serviceRegistry.AddAutoInject(startup);
                startup.ConfigureServices(serviceRegistry, startupContext);
            }

            _container = new Container(serviceRegistry);
            _setup     = null;

            startups.Clear();
            startups = null;

            foreach (var informService in _container.GetServices <IAfterDIContainerBuildListener>())
            {
                informService.AfterDIContainerBuild();
            }
        }