public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddDefaultPolicy(config => { config.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().WithExposedHeaders(Headers); }); }); services.AddAuthentication("Bearer").AddJwtBearer("Bearer", config => { config.Authority = Configuration["Services:Authority"]; config.Audience = "Appraisal"; config.RequireHttpsMetadata = false; }); services.AddHttpClient("EmployeeService", config => { config.BaseAddress = new Uri(Configuration["Services:employee"]); config.DefaultRequestHeaders.Clear(); config.DefaultRequestHeaders.Add("Accept", "application/json"); }).AddTransientHttpErrorPolicy(p => p.WaitAndRetryAsync(5, _ => TimeSpan.FromMilliseconds(500))); services.AddHttpClient("discoveryEndpoint", config => { config.BaseAddress = new Uri(Configuration["Services:Authority"]); config.DefaultRequestHeaders.Clear(); config.DefaultRequestHeaders.Add("Accept", "application/json"); }); services.AddHttpClient("Auth", config => { config.BaseAddress = new Uri(Configuration["Services:Auth"]); config.DefaultRequestHeaders.Clear(); config.DefaultRequestHeaders.Add("Accept", "application/json"); }); //services.AddHttpContextAccessor(); services.AddTransient <IDbContext, EdgeAppraisalContext>(ctx => EdgeAppraisalContext.Create( Configuration.GetSection("DefaultConnection:ConnectionString").Value, Configuration.GetSection("DefaultConnection:DataBaseName").Value)); services.AddTransient <ISGClient, SGClient>(ctx => SGClient.Create( Configuration.GetSection("SendGrid:SENDGRID_API_KEY").Value)); services.AddTransient(typeof(EmailDispatcher)); services.AddTransient <IEmailSender, EmailSender>(); services.AddTransient <IKeyResultArea, KeyResultAreaService>(); services.AddTransient <IAppraisalConfig, AppraisalConfigService>(); services.AddTransient <IAppraisalResult, AppraisalResultService>(); services.AddTransient <ITeamRepository, TeamService>(); services.AddTransient <IAppraisalFinalResult, AppraisalFinalResultService>(); services.AddTransient <ICoreValue, CoreValueService>(); services.AddScoped <ITokenAccesor, TokenAccessorService>(); services.AddTransient(typeof(AuthService)); services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); services.Configure <MvcOptions>(config => { var newtonsoftJsonOutputFormatter = config.OutputFormatters.OfType <NewtonsoftJsonOutputFormatter>()?.FirstOrDefault(); if (newtonsoftJsonOutputFormatter != null) { newtonsoftJsonOutputFormatter.SupportedMediaTypes.Add("application/vnd.marvin.hateoas+json"); } }); services.AddControllers(setupAction => { setupAction.ReturnHttpNotAcceptable = true; }) .AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver()) .AddXmlDataContractSerializerFormatters(); }
public void ConfigureServices(IServiceCollection services) { var AuthConnectionString = configuration.GetConnectionString("Auth"); var Identity4ConnectionString = configuration.GetConnectionString("Identity4"); services.AddCors(options => { options.AddDefaultPolicy(cors => cors.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() ); }); services.AddDbContext <EdgeDbContext>(config => { config.UseSqlServer(AuthConnectionString, options => { options.EnableRetryOnFailure(); }); }) .AddIdentity <ApplicationUser, ApplicationRole>(config => { config.Password.RequiredLength = 4; config.Password.RequireDigit = false; config.Password.RequiredUniqueChars = 0; config.Password.RequireNonAlphanumeric = false; config.Password.RequireUppercase = false; config.Password.RequireLowercase = false; }) .AddEntityFrameworkStores <EdgeDbContext>() .AddDefaultTokenProviders(); services.ConfigureApplicationCookie(config => { config.LoginPath = "/Auth/Authenticate"; config.Cookie.Name = "IdentityServer.Cookie"; config.LogoutPath = "/Auth/signout"; }); var assembly = typeof(Startup).Assembly.GetName().Name; //var certificate = new X509Certificate2() services.AddIdentityServer() .AddCorsPolicyService <CorsPolicyImplementation>() .AddAspNetIdentity <ApplicationUser>() .AddConfigurationStore(options => { options.ConfigureDbContext = b => b.UseSqlServer(Identity4ConnectionString, sql => sql.MigrationsAssembly(assembly)); }) .AddOperationalStore(options => { options.ConfigureDbContext = b => b.UseSqlServer(Identity4ConnectionString, sql => sql.MigrationsAssembly(assembly)); }) .AddDeveloperSigningCredential(); //.AddSigningCredential() services.AddTransient <ISGClient, SGClient>(ctx => SGClient.Create( configuration.GetSection("SendGrid:SENDGRID_API_KEY").Value)); services.AddTransient(typeof(EmailDispatcher)); services.AddTransient <IEmailSender, EmailService>(); services.AddTransient <IAuthInterface, AuthServices>(); services.AddTransient <IExternalServiceInterface, ExternalApprisalService>(); services.AddControllersWithViews() .AddRazorRuntimeCompilation(); }