コード例 #1
0
ファイル: Program.cs プロジェクト: Hugoberry/WEB
        private static void ConfigurationDependencies()
        {
            var dbConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            ServiceCollection = new ServiceCollection()
                                //.AddDbContextPool<NiisWebContext>(options => options.UseSqlServer(dbConnectionString), poolSize: 8)
                                .AddDbContext <NiisWebContext>(options => options.UseSqlServer(dbConnectionString))
                                .AddTransient <DbContext, NiisWebContext>()
                                .AddTransient <IExecutor, NiisRepository>()
                                .AddTransient <IAmbientContext, AmbientContext>()
                                .AddTransient <IUnitOfWork, UnitOfWork>()
                                .AddTransient <IObjectResolver, ObjectResolver>()
                                .AddTransient <IRuleExecutor, RuleExecutor>()
                                .AddTransient <IDateTimeProvider, DateTimeProvider>()
                                .AddTransient <ICalendarProvider, CalendarProvider>()
                                .AddTransient <IIntegrationStatusUpdater, IntegrationStatusUpdater>()
                                .AddTransient <IIntegrationDocumentUpdater, IntegrationDocumentUpdater>()
                                .AddTransient <IDicTypeResolver, DicTypeResolver>()
                                .AddTransient <IFileStorage, MinioFileStorage>()
                                .AddTransient <DictionaryHelper>()
                                .AddSingleton <NiisAmbientContext>()
                                .AddSingleton <RequestAppellationOfOriginWorkflow>()
                                .AddNiisWorkFlowBusinessLogicDependencies()
                                .AddAutoMapper(mapperConfig => mapperConfig.AddProfiles(typeof(Program).Assembly))
                                .AddWorkflowServices();


            ServiceProvider = ServiceCollection.BuildServiceProvider();
            var _   = new AmbientContext(ServiceProvider);
            var __  = new NiisAmbientContext(ServiceProvider, null);
            var ___ = new NiisWorkflowAmbientContext(ServiceProvider);
        }
コード例 #2
0
        /// <summary>
        /// Этот метод вызывается во время выполнения. Используйте этот метод для добавления сервисов в контейнер.
        /// </summary>
        /// <param name="services">Определяет контракт для набора дескрипторов сервисов.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAutoMapper(typeof(Model.Mappings.AutoMapperAssemblyPointer).Assembly);

            #region Глобальные зависимости
            //services
            //.AddDbContextPool<NiisWebContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
            //    sqlServerOptions => sqlServerOptions.CommandTimeout(180)))
            services
            .AddDbContext <NiisWebContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
                                                                           sqlServerOptions => sqlServerOptions.CommandTimeout(300)))
            .AddTransient <DbContext, NiisWebContext>()
            .AddTransient <IExecutor, NiisRepository>()
            .AddTransient <IAmbientContext, AmbientContext>()
            .AddTransient <IUnitOfWork, UnitOfWork>()
            .AddTransient <IObjectResolver, ObjectResolver>();

            services
            .AddCommonTypeServiceCollection()
            .AddNiisAuthenticationServiceDependencies()
            .AddNiisBusinessLogicDependencies()
            .AddNiisWorkFlowBusinessLogicDependencies();     // Add all Iserv.Niis.BusinessLogic dependencies
            #endregion

            services.AddTransient <IFileStorage, MinioFileStorage>();

            services.AddTransient <IGenerateHash, GenerateHash>();
            services.AddTransient <IEventLogger, EventLogger>();
            //services.AddTransient<IDicTypeResolver, DicTypeResolver>();
            //services.AddTransient<DictionaryHelper>();

            services.AddScoped <IImportRequestHelper, ImportRequestHelper>();
            services.AddScoped <IImportPaymentsHelper, ImportPaymentsHelper>();
            services.AddScoped <IImportDocumentsHelper, ImportDocumentsHelper>();
            services.AddScoped <IImportContractsHelper, ImportContractsHelper>();
            services.AddScoped <IBaseImportHelper, BaseImportHelper>();

            services.AddScoped <IAutoImportRequestService, AutoImportRequestService>();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            //Создается экземпляр в конце этого метода
            var _  = new AmbientContext(services.BuildServiceProvider());
            var __ = new NiisAmbientContext(services.BuildServiceProvider(), Configuration);
        }
コード例 #3
0
ファイル: BaseWorkflowTest.cs プロジェクト: Hugoberry/WEB
        public void OneTimeSetUp()
        {
            ServiceCollection = new ServiceCollection()
                                .AddEntityFrameworkInMemoryDatabase()
                                .AddDbContext <NiisWebContext>(opt => opt.UseInMemoryDatabase($"Niis_test_in_memory_data_base_{Guid.NewGuid()}")
                                                               .ConfigureWarnings(config => config.Ignore(InMemoryEventId.TransactionIgnoredWarning)))
                                .AddScoped <DbContext, NiisWebContext>()
                                .AddTransient <IExecutor, Executor>()
                                .AddTransient <IAmbientContext, AmbientContext>()
                                .AddTransient <IUnitOfWork, UnitOfWork>()
                                .AddTransient <IObjectResolver, ObjectResolver>()
                                .AddTransient <IRuleExecutor, RuleExecutor>()
                                .AddTransient <IDateTimeProvider, DateTimeProvider>()
                                .AddSingleton <NiisAmbientContext>();

            AddTestHandlers(ServiceCollection);
            AddTestCommands(ServiceCollection);

            ServiceProvider = ServiceCollection.BuildServiceProvider();
            var _  = new AmbientContext(ServiceProvider);
            var __ = new NiisAmbientContext(ServiceProvider, null);
        }
コード例 #4
0
ファイル: Startup.cs プロジェクト: Hugoberry/WEB
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAutoMapper(typeof(Model.Mappings.AutoMapperAssemblyPointer).Assembly);

            #region Swagger

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "NIIS API", Version = "v1"
                });
            });

            #endregion

            #region Глобальные зависимости
            //services
            //.AddDbContextPool<NiisWebContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
            //                                                                    sqlServerOptions => sqlServerOptions.CommandTimeout(180)), poolSize: 128)
            services.AddDbContext <NiisWebContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
                                                                                   sqlServerOptions => sqlServerOptions.CommandTimeout(300)))

            .AddTransient <DbContext, NiisWebContext>()
            //.AddTransient<IExecutor, Executor>()
            .AddTransient <IExecutor, NiisRepository>()
            //.AddScoped<IExecutor, NiisRepository>()
            .AddTransient <IAmbientContext, AmbientContext>()
            .AddTransient <IUnitOfWork, UnitOfWork>()
            .AddTransient <IObjectResolver, ObjectResolver>();


            #endregion

            #region Локальные зависимости проекта

            //TODO: необходимо распределить корректно зависимости. Сейчас слишком много мест.
            services
            .AddCommonTypeServiceCollection();

            services
            .AddNiisAuthenticationServiceDependencies()
            .AddNiisBusinessLogicDependencies()     // Add all Iserv.Niis.BusinessLogic dependencies
            .AddNiisDataBridgeDependencies()        // Add all  Iserv.Niis.DataBridge dependencies
            .AddNiisWorkFlowBusinessLogicDependencies()
            .AddNiisReportBusinessLogicDependencies()
            .AddNiisDIDependencies()
            .AddNiisServicesDependencies();


            services.AddTransient <IAutoRouteStageHelper, AutoRouteStageHelper>();

            services.AddWorkflowServices();

            services.Configure <ConfigExternalService>(opt => Configuration.GetSection("ConfigExternalService").Bind(opt));
            services.AddTransient <IIntegrationOneCApiClient, IntegrationOneCApiClient>();

            #endregion

            #region Authoriazation settings

            services.AddScoped <IUserClaimsPrincipalFactory <ApplicationUser>, AppClaimsPrincipalFactory>();
            services.AddTransient <IJwtFactory, JwtFactory>();

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options => ConfigurationOptions.JwtBearerOptions(options, Configuration))
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => options.SessionStore = new MemoryCacheTicketStore());

            services.AddIdentity <ApplicationUser, ApplicationRole>(ConfigurationOptions.IdentityOptions).AddEntityFrameworkStores <NiisWebContext>();

            services.AddMvc(options =>
            {
                options.Filters.Add(typeof(GlobalExceptionFilter));

                var authorizePolicy = new AuthorizationPolicyBuilder()
                                      .RequireAuthenticatedUser()
                                      .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                                      .Build();
                options.Filters.Add(new AuthorizeFilter(authorizePolicy));
            })
            .AddSessionStateTempDataProvider();

            services.AddAuthorization(options =>
            {
                const string prmName = KeyFor.JwtClaimIdentifier.Permission;

                options.AddPolicy(KeyFor.Policy.HasAccessToJournal, policy => policy.RequireClaim(prmName, KeyFor.Permission.JournalModule));
                options.AddPolicy(KeyFor.Policy.HasAccessToViewStaffTasks, policy => policy.RequireClaim(prmName, KeyFor.Permission.JournalViewStaffTasks));
                options.AddPolicy(KeyFor.Policy.HasAccessToAdministration, policy => policy.RequireClaim(prmName, KeyFor.Permission.AdministrationModule));
            });

            #endregion

            #region Hosted services

            services.AddHostedService <ImportPaymentsFrom1CHostedService>();

            #endregion

            //Создается экземпляр в конце этого метода
            var _   = new AmbientContext(services.BuildServiceProvider());
            var __  = new NiisAmbientContext(services.BuildServiceProvider(), Configuration);
            var ___ = new NiisWorkflowAmbientContext(services.BuildServiceProvider());
        }