示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            InitializeContainer(app);

            container.Register <ErrorExceptionResolver>();

            var assemblyParameter = new BuildAssemblyParameter();
            var context           = new ApplicationContextImpl(assemblyParameter); // アプリケーションコンテキスト

            context.SetDiContainer(container);
            container.RegisterSingleton <IApplicationContext>(context);
            container.RegisterSingleton <IBuildAssemblyParameter>(assemblyParameter);
            container.Register <ICategoryRepository, CategoryRepository>();
            container.Register <IContentRepository, ContentRepository>();
            container.Register <IFileMappingInfoRepository, FileMappingInfoRepository>();
            container.Register <IWorkspaceRepository, WorkspaceRepository>();
            container.Register <IAppAppMetaInfoRepository, AppAppMetaInfoRepository>();
            container.Register <IThumbnailAppMetaInfoRepository, ThumbnailAppMetaInfoRepository>();
            container.Register <IThumbnailRepository, ThumbnailRepository>();
            container.Register <IAppDbContext, AppDbContext>(Lifestyle.Scoped);
            container.Register <IThumbnailDbContext, ThumbnailDbContext>(Lifestyle.Scoped);
            container.Register <IThumbnailBuilder, ThumbnailBuilder>();

            var extentionManager = new ExtentionManager(container);

            container.RegisterSingleton <ExtentionManager>(extentionManager);
            extentionManager.InitializePlugin(context.ExtentionDirectoryPath);
            extentionManager.CompletePlugin();
            container.Verify();

            using (AsyncScopedLifestyle.BeginScope(container))
            {
                var appCtx = (ApplicationContextImpl)container.GetInstance <IApplicationContext>();
                appCtx.Initialize();
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            using (AsyncScopedLifestyle.BeginScope(container))
            {
                // 拡張機能: START
                extentionManager.Execute(ExtentionCutpointType.START, new CutpointStartParameter {
                    WorkspaceId = 1L
                });
            }

            app.Use((c, next) => container.GetInstance <ErrorExceptionResolver>().Invoke(c, next));
            app.UseMvc();
        }
        /// <summary>
        /// DIコンテナへ生成インスタンスの登録を行います
        /// </summary>
        /// <param name="container"></param>
        public void SetDiContainer(SimpleInjector.Container container)
        {
            this.mContainer = container;

            container.RegisterInstance <IApplicationContext> (this);
            container.Register <ICategoryRepository, CategoryRepository> ();
            container.Register <IContentRepository, ContentRepository> ();
            container.Register <IEventLogRepository, EventLogRepository> ();
            container.Register <IFileMappingInfoRepository, FileMappingInfoRepository> ();
            container.Register <ILabelRepository, LabelRepository> ();
            container.Register <IWorkspaceRepository, WorkspaceRepository> ();
            container.Register <IAppAppMetaInfoRepository, AppAppMetaInfoRepository> ();
            container.Register <IThumbnailAppMetaInfoRepository, ThumbnailAppMetaInfoRepository> ();
            container.Register <IThumbnailRepository, ThumbnailRepository> ();
            container.Register <ApiResponseBuilder> ();
            container.Register <IAppDbContext, AppDbContext> (Lifestyle.Scoped);
            container.Register <IThumbnailDbContext, ThumbnailDbContext> (Lifestyle.Scoped);
            container.Register <IThumbnailBuilder, ThumbnailBuilder> ();
            container.Register <IFileUpdateRunner, FileUpdateRunner> ();

            // サービス登録
            container.Register <IVirtualFileSystemService, VirtualFileSystemServiceImpl> ();

            // メッセージング機能
            container.Register <IMessagingScopeContext, MessagingScopeContext> (Lifestyle.Scoped);
            var messagingManager = new MessagingManager(container);

            container.RegisterInstance <MessagingManager> (messagingManager);
            container.RegisterInstance <IMessagingManager> (messagingManager);

            // 拡張機能
            var extentionManager = new ExtentionManager(container);

            //extentionManager.AddPlugin (typeof (InitializeBuildExtention)); // 開発中は常に拡張機能を読み込む
            //extentionManager.AddPlugin (typeof (WebScribeExtention)); // 開発中は常に拡張機能を読み込む
            container.RegisterInstance <ExtentionManager> (extentionManager);
            extentionManager.InitializePlugin(ExtentionDirectoryPath);
            extentionManager.CompletePlugin();

            // VFS機能
            var virtualFileUpdateWatchService = new VirtualFileUpdateWatchService(container);

            container.RegisterInstance <VirtualFileUpdateWatchService> (virtualFileUpdateWatchService);
        }
示例#3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            InitializeContainer(app);

            var appConfig = new AppSettings();

            Configuration.Bind("AppSettings", appConfig);

            container.Register <ErrorExceptionResolver>();
            var assemblyParameter = new BuildAssemblyParameter(appConfig);
            var context           = new ApplicationContextImpl(assemblyParameter); // アプリケーションコンテキスト

            context.SetDiContainer(container);
            container.RegisterInstance <IApplicationContext>(context);
            container.RegisterInstance <IBuildAssemblyParameter>(assemblyParameter);
            container.Register <ICategoryRepository, CategoryRepository>();
            container.Register <IContentRepository, ContentRepository>();
            container.Register <IEventLogRepository, EventLogRepository>();
            container.Register <IFileMappingInfoRepository, FileMappingInfoRepository>();
            container.Register <ILabelRepository, LabelRepository>();
            container.Register <IWorkspaceRepository, WorkspaceRepository>();
            container.Register <IAppAppMetaInfoRepository, AppAppMetaInfoRepository>();
            container.Register <IThumbnailAppMetaInfoRepository, ThumbnailAppMetaInfoRepository>();
            container.Register <IThumbnailRepository, ThumbnailRepository>();
            container.Register <ApiResponseBuilder>();
            container.Register <IAppDbContext, AppDbContext>(Lifestyle.Scoped);
            container.Register <IThumbnailDbContext, ThumbnailDbContext>(Lifestyle.Scoped);
            container.Register <IThumbnailBuilder, ThumbnailBuilder>();
            container.Register <IFileUpdateRunner, FileUpdateRunner>();

            var messagingManager = new MessagingManager(container);

            container.RegisterInstance <MessagingManager>(messagingManager);
            container.RegisterInstance <IMessagingManager>(messagingManager);

            var extentionManager = new ExtentionManager(container);

            extentionManager.AddPlugin(typeof(FullBuildExtention)); // 開発中は常に拡張機能を読み込む
            extentionManager.AddPlugin(typeof(WebScribeExtention)); // 開発中は常に拡張機能を読み込む
            container.RegisterInstance <ExtentionManager>(extentionManager);
            extentionManager.InitializePlugin(context.ExtentionDirectoryPath);
            extentionManager.CompletePlugin();

            var vspFileUpdateWatchManager = new VspFileUpdateWatchManager(container);

            container.RegisterInstance <VspFileUpdateWatchManager>(vspFileUpdateWatchManager);

            container.Verify();

            using (AsyncScopedLifestyle.BeginScope(container))
            {
                var appCtx = (ApplicationContextImpl)container.GetInstance <IApplicationContext>();
                appCtx.Initialize();

                // デフォルトワークスペースが登録済みかチェックする
                var workspaceRepository = container.GetInstance <IWorkspaceRepository>();
                var workspace           = workspaceRepository.Load(1L);
                if (workspace == null)
                {
                    if (appConfig.Workspace == null)
                    {
                        throw new ApplicationException("デフォルトワークスペースの設定が必要です。");
                    }

                    // デフォルトワークスペースを新規登録する
                    workspace      = workspaceRepository.New();
                    workspace.Name = appConfig.Workspace.Name;
                    if (appConfig.Workspace.RelativeApplicationDirectoryBasePath)
                    {
                        workspace.PhysicalPath = Path.Combine(appCtx.ApplicationDirectoryPath, appConfig.Workspace.PhysicalPath);
                        workspace.VirtualPath  = Path.Combine(appCtx.ApplicationDirectoryPath, appConfig.Workspace.VirtualPath);
                    }
                    else
                    {
                        workspace.PhysicalPath = appConfig.Workspace.PhysicalPath;
                        workspace.VirtualPath  = appConfig.Workspace.VirtualPath;
                    }
                    workspaceRepository.Save();

                    _logger.Info($"デフォルトワークスペースを作成しました。 Name:{workspace.Name}");
                }
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            using (AsyncScopedLifestyle.BeginScope(container))
            {
                // カットポイント「INIT」を呼び出す
                extentionManager.Execute(ExtentionCutpointType.INIT);
            }

            using (AsyncScopedLifestyle.BeginScope(container))
            {
                // カットポイント「START」を呼び出す
                extentionManager.Execute(ExtentionCutpointType.START, new CutpointStartParameter {
                    WorkspaceId = 1L
                });
            }

            // 監視開始
            using (AsyncScopedLifestyle.BeginScope(container))
            {
                var workspaceRepository = container.GetInstance <IWorkspaceRepository>();
                var workspace           = workspaceRepository.Load(1L);
                vspFileUpdateWatchManager.StartWatch(workspace);
            }

            app.Use((c, next) => container.GetInstance <ErrorExceptionResolver>().Invoke(c, next));
            app.UseMvc();
        }