/// <summary> /// Configuration for services. /// </summary> /// <param name="services">The services collection.</param> public void ConfigureServices(IServiceCollection services) { var constr = this.Configuration.GetConnectionString("default"); var imageSection = this.Configuration.GetSection("image"); var authDataLayer = CatiDataLayerFactory.CreateAuthDataLayer(constr); var catiData = CatiDataLayerFactory.CreateDataLayer(constr); var imageData = CatiDataLayerFactory.CreateImageDataLayer(constr); var storageConnection = this.Configuration.GetConnectionString("images"); var imageWidths = imageSection.GetSection("widths").Get <int[]>(); var imageUploader = ImageUploaderFactory.Create(imageData, storageConnection, imageWidths); var trace = new WebAppTrace(this.loggerFactory); trace.TraceInfo("Logger has been initialized."); var contentTransformer = new MarkdownProcessor(); var postTranslator = PostTranslatorFactory.Create(authDataLayer, contentTransformer, imageData, imageUploader); // Add the data layers. services.AddSingleton <IProgramTrace>(trace); services.AddSingleton <ICatiDataLayer>(catiData); services.AddSingleton <ICatiAuthDataLayer>(authDataLayer); services.AddSingleton <IPostTranslator>(postTranslator); services.AddSingleton <ICatiImageDataLayer>(imageData); services.AddSingleton <IContentTransformer>(contentTransformer); services.AddSingleton <IImageUploader>(imageUploader); services.AddSingleton <IAuthorizationHandler, DefaultAuthorizationHandler>().AddAuthorization( options => { options.AddPolicy("default", policy => policy.Requirements.Add(new DefaultAuthorizationRequirement())); }); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie( config => { config.Cookie.HttpOnly = true; //config.Cookie.Domain = "caticake.azurewebsites.net"; config.Cookie.Name = "CatiCookie"; config.Cookie.SameSite = SameSiteMode.None; config.Cookie.SecurePolicy = CookieSecurePolicy.Always; config.Cookie.Path = ""; config.Events.OnRedirectToLogin = options => { options.Response.StatusCode = 401; return(Task.CompletedTask); }; config.Events.OnRedirectToAccessDenied = options => { options.Response.StatusCode = 401; return(Task.CompletedTask); }; config.Events.OnRedirectToReturnUrl = options => { options.Response.StatusCode = 401; return(Task.CompletedTask); }; }); services.AddCors( options => { options.AddPolicy( "default", policy => { policy.AllowAnyHeader(); policy.AllowAnyMethod(); policy.AllowCredentials(); policy.AllowAnyOrigin(); }); }); services.AddMvc( config => { // config.Filters.Add(new AuthorizationFilter(authDataLayer)); config.Filters.Add(new CatiExceptionFilter()); config.Filters.Add(new ValidationFilter()); }); // Add the documentation services.AddSwaggerGen( config => { config.SwaggerDoc("v1", new Info { Title = "Cati Lyfe Api", Version = "0.0.0.0.0.0.1" }); }); }
/// <summary> /// Configuration for services. /// </summary> /// <param name="services">The services collection.</param> public void ConfigureServices(IServiceCollection services) { var constr = this.Configuration.GetConnectionString("default"); var security = this.Configuration.GetSection("Security"); var passwordSalt = security["salt"]; var authDataLayer = CatiDataLayerFactory.CreateAuthDataLayer(constr); // Add the data layers. services.AddSingleton <ICatiDataLayer>(CatiDataLayerFactory.CreateDataLayer(constr)); services.AddSingleton <ICatiAuthDataLayer>(authDataLayer); services.AddSingleton <IPasswordHelper>(new PasswordGenerator(passwordSalt)); services.AddSingleton <IContentTransformer>(new MarkdownProcessor()); services.AddSingleton <IAuthorizationHandler, DefaultAuthorizationHandler>().AddAuthorization( options => { options.AddPolicy("default", policy => policy.Requirements.Add(new DefaultAuthorizationRequirement())); }); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie( config => { config.Cookie.HttpOnly = true; //config.Cookie.Domain = "caticake.azurewebsites.net"; config.Cookie.Name = "CatiCookie"; config.Cookie.SameSite = SameSiteMode.None; config.Cookie.SecurePolicy = CookieSecurePolicy.Always; config.Cookie.Path = ""; config.Events.OnRedirectToLogin = options => { options.Response.StatusCode = 401; return(Task.CompletedTask); }; config.Events.OnRedirectToAccessDenied = options => { options.Response.StatusCode = 401; return(Task.CompletedTask); }; config.Events.OnRedirectToReturnUrl = options => { options.Response.StatusCode = 401; return(Task.CompletedTask); }; }); services.AddCors( options => { options.AddPolicy( "default", policy => { policy.AllowAnyHeader(); policy.AllowAnyMethod(); policy.AllowCredentials(); policy.AllowAnyOrigin(); }); }); services.AddMvc( config => { // config.Filters.Add(new AuthorizationFilter(authDataLayer)); config.Filters.Add(new CatiExceptionFilter()); config.Filters.Add(new ValidationFilter()); }); // Add the documentation services.AddSwaggerGen( config => { config.SwaggerDoc("v1", new Info { Title = "Cati Lyfe Api", Version = "0.0.0.0.0.0.1" }); }); }