public IEnumerable <NotificationDto> GetNewNotifications() { var currentUser = User.Identity.GetUserId(); var notifications = _unitOfWork.Notifications.GetNewNotificationsFor(currentUser); var mapper = MappingConfig.GetMapper(); return(notifications.Select(mapper.Map <Notification, NotificationDto>)); }
public void ConfigureBaseServices(IServiceCollection services, ServiceLifetime lifetime) { services.Configure <ApiSettings>(_configuration.GetSection("APISettings")); services.Configure <StaticUrls>(_configuration.GetSection("StaticUrls")); services.Configure <GoogleSettings>(_configuration.GetSection("GoogleOAuth")); services.Configure <FileDirectoryPathSettings>(_configuration.GetSection("FileDirectoryPath")); services.Configure <SmtpSettings>(_configuration.GetSection("SmtpSettings")); var pathSettings = _configuration.GetSection("FileDirectoryPath").Get <FileDirectoryPathSettings>(); var cropSizes = _configuration.GetSection("CropSizes:SizesStr").Get <string>(); CropSizesSettings.SetSizes(cropSizes); var fileTemplate = _configuration.GetSection("FileTemplateUrl:FileTemplate").Get <string>(); var imageTemplate = _configuration.GetSection("FileTemplateUrl:ImageTemplate").Get <string>(); PathTemplates.SetFilePathTemplate(fileTemplate); PathTemplates.SetImagePathTemplate(imageTemplate); var dbSettings = new DbSettings { DB_HOST = _configuration.GetSection("DB_HOST").Value, DB_PORT = _configuration.GetSection("DB_PORT").Value, DB_USER = _configuration.GetSection("DB_USER").Value, DB_NAME = _configuration.GetSection("DB_NAME").Value, DB_PASSWORD = _configuration.GetSection("DB_PASSWORD").Value }; Console.WriteLine($"Connection string: {dbSettings?.PostgresConnectionString}"); Console.WriteLine($"File path: {pathSettings?.FileRootPath}"); Console.WriteLine($"Email templates: {pathSettings?.EmailTemplatePath}"); Console.WriteLine($"Image path template: {imageTemplate}"); services.AddSerilog(dbSettings); services.AddDbContext <SquadioDbContext>(builder => builder .EnableSensitiveDataLogging() .UseNpgsql(dbSettings.PostgresConnectionString, optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(SquadioDbContext).Assembly.FullName))); DependencyInjectionModule.Load(services, lifetime); services.AddSingleton(MappingConfig.GetMapper()); services.AddMemoryCache(); }
public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy(MyAllowOrigins, builder => builder // .SetIsOriginAllowed(origin => true) // .WithOrigins("http://185.227.108.172") .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() // .AllowCredentials() ); }); services.Configure <ApiBehaviorOptions>(options => options.SuppressModelStateInvalidFilter = true); var dbSettings = new DbSettings { DB_HOST = Configuration.GetSection("DB_HOST").Value, DB_PORT = Configuration.GetSection("DB_PORT").Value, DB_USER = Configuration.GetSection("DB_USER").Value, DB_PASSWORD = Configuration.GetSection("DB_PASSWORD").Value, DB_NAME = Configuration.GetSection("DB_NAME").Value, }; services.AddDbContext <ApplicationDbContext>(options => options .EnableSensitiveDataLogging() .UseNpgsql(dbSettings.DbConnectionString, builder => builder.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName))); services.AddControllers(options => { options.Filters.Add(typeof(ValidateModelAttribute)); options.Filters.Add(typeof(StatusCodeFilter)); }).AddFluentValidation( fv => fv.RegisterValidatorsFromAssemblyContaining <DTO.DependencyInjectionModule>()); services.AddSingleton(MappingConfig.GetMapper()); DependencyInjectionModule.Load(services); }
public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy(MyAllowOrigins, builder => builder // .WithOrigins("http://localhost:63342") .AllowAnyOrigin() // .AllowCredentials() .AllowAnyHeader() .AllowAnyMethod() ); }); services.Configure <ApiBehaviorOptions>(options => options.SuppressModelStateInvalidFilter = true); services.Configure <ApiSettings>(Configuration.GetSection("AppSettings:APISettings")); var dbSettings = new DbSettings { DB_HOST = Configuration.GetSection("DB_HOST").Value, DB_PORT = Configuration.GetSection("DB_PORT").Value, DB_USER = Configuration.GetSection("DB_USER").Value, DB_PASSWORD = Configuration.GetSection("DB_PASSWORD").Value, DB_NAME = Configuration.GetSection("DB_NAME").Value }; services.AddDbContext <ApplicationDbContext>(options => options.UseNpgsql(dbSettings.DbConnectionString, optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName))); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { var apiSettings = Configuration.GetSection("AppSettings:APISettings").Get <ApiSettings>(); // options.RequireHttpsMetadata = true; options.TokenValidationParameters = new TokenValidationParameters { ClockSkew = TimeSpan.Zero, ValidateAudience = true, ValidAudience = apiSettings.AUDIENCE, ValidateIssuer = true, ValidIssuer = apiSettings.ISSUER, ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(apiSettings.PublicKey)), // To allow return custom response for expired token ValidateLifetime = false, }; options.Events = new JwtBearerEvents { OnMessageReceived = context => { var accessToken = context.Request.Query["access_token"]; var path = context.HttpContext.Request.Path; if (!String.IsNullOrEmpty(path) && path.StartsWithSegments("/api/ws")) { context.Token = accessToken; } return(Task.CompletedTask); } }; }); services.AddAuthorization(); services.AddSignalR(); services.AddControllers(options => { options.Filters.Add(typeof(ValidateModelAttribute)); options.Filters.Add(typeof(StatusCodeFilter)); }) .AddFluentValidation(fv => { ValidatorConfigurationOverload.Override(); fv.RegisterValidatorsFromAssemblyContaining <DTO.DependencyInjectionModule>(); }); services.AddDirectoryBrowser(); services.AddSingleton(MappingConfig.GetMapper()); DependencyInjectionModule.Load(services); }