public UserDaoTests() { _logger = new LoggerFactory().AddConsole().CreateLogger <IDaoFactory>(); var _daoFactory = DaoFactories.GetFactory(DatabaseProvider.Postgres, "host=localhost;port=5432;username=postgres;password=admin;database=vuetest", _logger); _dao = _daoFactory.UserDao; }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (!context.HttpContext.Request.Headers.TryGetValue(ApiKeyHeaderName, out var requestApiKey)) { context.Result = new UnauthorizedResult(); return; } if (!Guid.TryParse(requestApiKey, out var guidOutput)) { context.Result = new UnauthorizedResult(); return; } //check cache first string _dpDbConnectionString = Environment.GetEnvironmentVariable("dpDbConnectionString"); IDaoFactory AdoNetDao = DaoFactories.GetFactory(DataProvider.AdoNet, _dpDbConnectionString); // int? userId = await AdoNetDao.UserDao.CheckUserAPIKey(potentialApiKey); //If we just want to get the userId for auth User user = await AdoNetDao.UserDao.GetUserFromAPIKey(requestApiKey); if (user == null) { context.Result = new UnauthorizedResult(); return; } context.HttpContext.Items.Add("user", user); await next(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddSoapCore(); var appsettings = Configuration.Get <Appsettings>(); var databaseConnectionSettings = appsettings.DatabaseConnectionSettings; if (databaseConnectionSettings == null) { _logger.LogWarning("Database doesn't initialized yet!"); return; } string connectionString = databaseConnectionSettings.PostgresDatabaseConnectionString; services.AddScoped(provider => { var logger = provider.GetService <ILogger <IDaoFactory> >(); return(DaoFactories.GetFactory(DatabaseProvider.SqlServer, connectionString, logger)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new UserService(daoFactory.UserDao)); }); }
public Service(IOptions <ConfigCS> config) { if (factory == null) { providerContext = new ProviderContext(); providerContext.ProviderName = config.Value.Provider.ToString(); providerContext.ProviderConnectionString = config.Value.DBServer; factory = DaoFactories.GetFactory(providerContext); BuildDAOFactory(); } }
private static void ConfigureServices(ServiceCollection services, DatabaseConnectionSettings settings) { services.AddScoped(provider => { var logger = provider.GetService <ILogger <IDaoFactory> >(); return(DaoFactories.GetFactory(settings, logger)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new RoleInDepartmentService(daoFactory.RoleInDepartmentDao)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new UserRoleInDepartmentService(daoFactory.UserRoleInDepartment)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new StudentGroupService(daoFactory.StudentGroupDao)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new StudyDirectionService(daoFactory.StudyDirectionDao)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new DisciplineTitleService(daoFactory.DisciplineTitleDao)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var disciplineTitleService = provider.GetService <DisciplineTitleService>(); var roleInDepartmentService = provider.GetService <RoleInDepartmentService>(); var userRoleInDepartmentService = provider.GetService <UserRoleInDepartmentService>(); var studyDirectionService = provider.GetService <StudyDirectionService>(); var studentGroupService = provider.GetService <StudentGroupService>(); var logger = provider.GetService <ILogger <DepartmentService> >(); return(new DepartmentService(daoFactory.DepartmentDao, roleInDepartmentService, userRoleInDepartmentService, disciplineTitleService, studyDirectionService, studentGroupService, logger)); }).AddLogging(builder => builder.AddConsole()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddDefaultPolicy( builder => { builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() .WithExposedHeaders("*"); }); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); string connectionString = AppSettings.MSSqlServerConnectionString; services.AddScoped(provider => { var logger = provider.GetService <ILogger <IDaoFactory> >(); return(DaoFactories.GetFactory(DataProvider.MSSql, connectionString, logger)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new InstructorService(daoFactory.InstructorDao)); }); services.AddScoped(provider => new AllUrlsScraperStrategy()); services.AddScoped <IAppendStrategyExtensionsReader>(provider => provider.GetService <AllUrlsScraperStrategy>()); services.AddScoped(provider => new ImagesSourcesScraperStrategy()); services.AddScoped <IAppendStrategyExtensionsReader>(provider => provider.GetService <ImagesSourcesScraperStrategy>()); services.AddScoped(provider => new DoesNotContainsProfileScraperStrategy()); services.AddScoped <IExcludeStrategyExtensionsReader>(provider => provider.GetService <DoesNotContainsProfileScraperStrategy>()); services.AddScoped(provider => { var logger = provider.GetService <ILogger <ScraperService> >(); return(new ScraperService(logger, provider.ComposeAppendStrategyReaders(), provider.ComposeExcludeStrategyReaders())); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddDefaultPolicy(builder => { builder .AllowAnyHeader() .AllowAnyMethod() .AllowAnyOrigin(); }); }); services.AddHttpContextAccessor(); services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); var connectionSettingsSection = Configuration.GetSection("ConnectionSettings"); var connectionSettings = connectionSettingsSection.Get <DatabaseConnectionSettings>(); services.AddScoped(provider => { var logger = provider.GetService <ILogger <IDaoFactory> >(); return(DaoFactories.GetFactory(connectionSettings, logger)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var logger = provider.GetService <ILogger <DeliveryService> >(); return(new DeliveryService(daoFactory.DeliveryDao, logger)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var logger = provider.GetService <ILogger <ProductService> >(); return(new ProductService(daoFactory.ProductDao, logger)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var logger = provider.GetService <ILogger <ReportService> >(); var productService = provider.GetService <ProductService>(); return(new CartService(daoFactory.CartDao, productService, logger)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var cartService = provider.GetService <CartService>(); var logger = provider.GetService <ILogger <OrderService> >(); return(new OrderService(daoFactory.OrderDao, cartService, logger)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var logger = provider.GetService <ILogger <ReportService> >(); return(new ReportService(daoFactory.CartReportDao)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var logger = provider.GetService <ILogger <UserLocationService> >(); return(new UserLocationService(daoFactory.UserLocationDao, logger)); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddDefaultPolicy(builder => { builder .AllowAnyHeader() .AllowAnyMethod() .AllowAnyOrigin(); }); }); services.AddControllers(); services.AddHttpContextAccessor(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); var appsettings = Configuration.Get <Appsettings>(); var emailSettings = appsettings.EmailConnectionSettings; var databaseConnectionSettings = appsettings.DatabaseConnectionSettings; // configure jwt authentication var key = Encoding.ASCII.GetBytes(appsettings.Secret); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = false, ValidateAudience = false }; }); if (databaseConnectionSettings == null) { _logger.LogWarning("Database doesn't initialized yet!"); return; } services.AddScoped(provider => { var logger = provider.GetService <ILogger <IDaoFactory> >(); return(DaoFactories.GetFactory(databaseConnectionSettings, logger)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new PinnedDisciplineService(daoFactory.PinnedDisciplineDao)); }); services.AddScoped(provider => { var httpContextAccessor = provider.GetService <IHttpContextAccessor>(); return(new FileService(_webHostEnvironment.ContentRootPath, httpContextAccessor)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new UserGraduateDegreeService(daoFactory.UserGraduateDegreeDao)); }); services.AddScoped(provider => { var logger = provider.GetService <ILogger <UserService> >(); var daoFactory = provider.GetService <IDaoFactory>(); var pinnedDisciplineService = provider.GetService <PinnedDisciplineService>(); var userGraduateDegreeService = provider.GetService <UserGraduateDegreeService>(); var httpAccessor = provider.GetService <IHttpContextAccessor>(); return(new UserService( daoFactory.UserDao, pinnedDisciplineService, userGraduateDegreeService, appsettings, httpAccessor, logger )); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new RoleInDepartmentService(daoFactory.RoleInDepartmentDao)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var roleInDepartmentService = provider.GetService <RoleInDepartmentService>(); var logger = provider.GetService <ILogger <RoleService> >(); return(new RoleService(daoFactory.RoleDao, roleInDepartmentService, logger)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new UserRoleInDepartmentService(daoFactory.UserRoleInDepartment)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new StudentGroupService(daoFactory.StudentGroupDao)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new StudyDirectionService(daoFactory.StudyDirectionDao)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); return(new DisciplineTitleService(daoFactory.DisciplineTitleDao)); }); #region егистрация стратегий распределения учебной нагрузки services.AddScoped <IGenerateStrategy>(provider => { var userService = provider.GetService <UserService>(); return(new ByPinnedDisciplinesStrategy(userService)); }); services.AddScoped <IGenerateStrategy>(provider => { var userService = provider.GetService <UserService>(); return(new ByGraduateDegreesStrategy(userService)); }); // Стратегия обработки коэффициентов должна быть зарегистрирована последней services.AddScoped <IGenerateStrategy>(provider => { var roleService = provider.GetService <RoleService>(); var userRoleInDepartmentService = provider.GetService <UserRoleInDepartmentService>(); return(new CalculateRatiosStrategy(roleService, userRoleInDepartmentService)); }); #endregion services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var userService = provider.GetService <UserService>(); return(new UserLoadService(daoFactory.UserLoadDao, userService)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var userLoadService = provider.GetService <UserLoadService>(); return(new StudyLoadService(daoFactory.StudyLoadDao, userLoadService)); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var studyLoadService = provider.GetService <StudyLoadService>(); var disciplineTitleService = provider.GetService <DisciplineTitleService>(); var studentGroupService = provider.GetService <StudentGroupService>(); return(new GroupDisciplineLoadService( daoFactory.GroupDisciplineLoadDao, studyLoadService, disciplineTitleService, studentGroupService )); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var departmentService = provider.GetService <DepartmentService>(); var disciplineTitleService = provider.GetService <DisciplineTitleService>(); var studentGroupService = provider.GetService <StudentGroupService>(); var studyDirectionService = provider.GetService <StudyDirectionService>(); var groupDisciplineLoadService = provider.GetService <GroupDisciplineLoadService>(); var studyLoadService = provider.GetService <StudyLoadService>(); var fileService = provider.GetService <FileService>(); var logger = provider.GetService <ILogger <DepartmentLoadService> >(); return(new DepartmentLoadService( daoFactory.DepartmentLoadDao, departmentService, disciplineTitleService, studentGroupService, groupDisciplineLoadService, studyLoadService, studyDirectionService, fileService, provider.ComposeGenerateStrategies(), logger )); }); services.AddScoped(provider => { var daoFactory = provider.GetService <IDaoFactory>(); var disciplineTitleService = provider.GetService <DisciplineTitleService>(); var roleInDepartmentService = provider.GetService <RoleInDepartmentService>(); var userRoleInDepartmentService = provider.GetService <UserRoleInDepartmentService>(); var studyDirectionService = provider.GetService <StudyDirectionService>(); var studentGroupService = provider.GetService <StudentGroupService>(); var logger = provider.GetService <ILogger <DepartmentService> >(); return(new DepartmentService( daoFactory.DepartmentDao, roleInDepartmentService, userRoleInDepartmentService, disciplineTitleService, studyDirectionService, studentGroupService, logger )); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddDefaultPolicy( builder => { builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() .WithExposedHeaders("*"); }); }); services.AddControllers(); services.AddHttpContextAccessor(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); // configure strongly typed settings objects var appSettings = Configuration.Get <Appsettings>(); // configure jwt authentication var key = Encoding.ASCII.GetBytes(appSettings.Secret); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = true, ValidIssuer = appSettings.Issuer, ValidateAudience = false }; }); var connectionSettings = appSettings.DatabaseConnectionSettings; var emailSettings = appSettings.EmailConnectionSettings; services.AddScoped(provider => { var logger = provider.GetService <ILogger <IDaoFactory> >(); return(DaoFactories.GetFactory(connectionSettings, logger)); }); services.AddScoped <IEmailService>(provider => { var logger = provider.GetService <ILogger <EmailService> >(); return(new EmailService(logger, emailSettings)); }); services.AddScoped <IUserService>(provider => { var logger = provider.GetService <ILogger <UserService> >(); var daoFactory = provider.GetService <IDaoFactory>(); var emailService = provider.GetService <IEmailService>(); var httpAccessor = provider.GetService <IHttpContextAccessor>(); return(new UserService(daoFactory.UserDao, emailService, appSettings, httpAccessor, logger)); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddDefaultPolicy(builder => { builder .AllowAnyHeader() .AllowAnyMethod() .AllowAnyOrigin(); }); }); services.AddHttpContextAccessor(); services.AddMvc(options => { options.InputFormatters.Insert(0, new DataContractInputFormatter()); options.OutputFormatters.Insert(0, new DataContractOutputFormatter()); }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2); string connectionString = Configuration.GetConnectionString("graph-master"); // configure strongly typed settings objects var appSettingsSection = Configuration.GetSection("AppSettings"); services.Configure <AppSettings>(appSettingsSection); // configure jwt authentication var appSettings = appSettingsSection.Get <AppSettings>(); var key = Encoding.ASCII.GetBytes(appSettings.Secret); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = false, ValidateAudience = false }; }); IDaoFactory factory = DaoFactories.GetFactory(DataProvider.AdoNet, connectionString); Environment.SetEnvironmentVariable("connectionString", connectionString); services.AddScoped <EmailService>(provider => { var appSettingsResolved = provider.GetService <IOptions <AppSettings> >(); return(new EmailService(appSettingsResolved.Value)); }); services.AddTransient <UserService>(provider => { var appSettingsResolved = provider.GetService <IOptions <AppSettings> >(); var emailService = provider.GetService <EmailService>(); var httpAccessor = provider.GetService <IHttpContextAccessor>(); return(new UserService(factory.UserDao, emailService, appSettingsResolved.Value, httpAccessor)); }); }