private static AdminService GetAdminService() { FantasyCriticUserManager userManager = null !; IFantasyCriticUserStore betaUserStore = new MySQLFantasyCriticUserStore(_betaConnectionString, _clock); IMasterGameRepo masterGameRepo = new MySQLMasterGameRepo(_betaConnectionString, betaUserStore); IFantasyCriticRepo fantasyCriticRepo = new MySQLFantasyCriticRepo(_betaConnectionString, betaUserStore, masterGameRepo); InterLeagueService interLeagueService = new InterLeagueService(fantasyCriticRepo, masterGameRepo); LeagueMemberService leagueMemberService = new LeagueMemberService(null !, fantasyCriticRepo, _clock); GameAcquisitionService gameAcquisitionService = new GameAcquisitionService(fantasyCriticRepo, masterGameRepo, leagueMemberService, _clock); ActionProcessingService actionProcessingService = new ActionProcessingService(gameAcquisitionService); FantasyCriticService fantasyCriticService = new FantasyCriticService(leagueMemberService, interLeagueService, fantasyCriticRepo, _clock); IOpenCriticService openCriticService = null !; IGGService ggService = null !; PatreonService patreonService = null !; IRDSManager rdsManager = null !; RoyaleService royaleService = null !; IHypeFactorService hypeFactorService = new LambdaHypeFactorService(_awsRegion, _betaBucket); AdminServiceConfiguration configuration = new AdminServiceConfiguration(true); var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var realHypeConstantsEnvironments = new List <string>() { "STAGING", "PRODUCTION" }; if (environment is not null && realHypeConstantsEnvironments.Contains(environment.ToUpper())) { configuration = new AdminServiceConfiguration(false); } return(new AdminService(fantasyCriticService, userManager, fantasyCriticRepo, masterGameRepo, interLeagueService, openCriticService, ggService, patreonService, _clock, rdsManager, royaleService, hypeFactorService, configuration, actionProcessingService)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { string connectionString = Configuration.GetConnectionString("DefaultConnection"); int validMinutes = Convert.ToInt32(Configuration["Tokens:ValidMinutes"]); var keyString = Configuration["Tokens:Key"]; var issuer = Configuration["Tokens:Issuer"]; var audience = Configuration["Tokens:Audience"]; IClock clock = SystemClock.Instance; // Add application services. var userStore = new MySQLFantasyCriticUserStore(connectionString, clock); var roleStore = new MySQLFantasyCriticRoleStore(connectionString); var fantasyCriticRepo = new MySQLFantasyCriticRepo(connectionString, userStore); var tokenService = new TokenService(keyString, issuer, audience, validMinutes); SendGridEmailSender sendGridEmailSender = new SendGridEmailSender(); services.AddHttpClient(); services.AddScoped <IFantasyCriticUserStore>(factory => userStore); services.AddScoped <IFantasyCriticRoleStore>(factory => roleStore); services.AddScoped <IFantasyCriticRepo>(factory => fantasyCriticRepo); services.AddScoped <IUserStore <FantasyCriticUser> >(factory => userStore); services.AddScoped <IRoleStore <FantasyCriticRole> >(factory => roleStore); services.AddScoped <FantasyCriticUserManager>(); services.AddScoped <FantasyCriticRoleManager>(); services.AddScoped <FantasyCriticService>(); services.AddTransient <IEmailSender>(factory => sendGridEmailSender); services.AddTransient <ISMSSender, SMSSender>(); services.AddTransient <ITokenService>(factory => tokenService); services.AddTransient <IClock>(factory => clock); services.AddHttpClient <IOpenCriticService, OpenCriticService>(); services.AddHttpClient <IOpenCriticService, OpenCriticService>(client => { client.BaseAddress = new Uri("https://api.opencritic.com/"); }); services.AddIdentity <FantasyCriticUser, FantasyCriticRole>(options => { options.Password.RequireDigit = false; options.Password.RequiredLength = 8; options.Password.RequireLowercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; }) .AddDefaultTokenProviders(); services.ConfigureApplicationCookie(opt => { opt.ExpireTimeSpan = TimeSpan.FromMinutes(validMinutes); opt.Events.OnRedirectToAccessDenied = ReplaceRedirector(HttpStatusCode.Forbidden, opt.Events.OnRedirectToAccessDenied); opt.Events.OnRedirectToLogin = ReplaceRedirector(HttpStatusCode.Unauthorized, opt.Events.OnRedirectToLogin); }); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(cfg => { cfg.TokenValidationParameters = new TokenValidationParameters() { ValidIssuer = issuer, ValidAudience = audience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(keyString)) }; // We have to hook the OnMessageReceived event in order to // allow the JWT authentication handler to read the access // token from the query string when a WebSocket or // Server-Sent Events request comes in. cfg.Events = new JwtBearerEvents { OnMessageReceived = context => { var accessToken = context.Request.Query["access_token"]; // If the request is for our hub... var path = context.HttpContext.Request.Path; if (!string.IsNullOrEmpty(accessToken) && (path.StartsWithSegments("/updatehub"))) { // Read the token out of the query string context.Token = accessToken; } return(Task.CompletedTask); } }; }); services.AddHsts(options => { options.Preload = true; options.IncludeSubDomains = true; options.MaxAge = TimeSpan.FromDays(60); }); services.AddHttpsRedirection(options => { options.RedirectStatusCode = StatusCodes.Status307TemporaryRedirect; options.HttpsPort = 443; }); // Add framework services. services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddJsonOptions(options => { options.SerializerSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb); }); services.AddSignalR(); }