aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Configurations/Extensions
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-02-13 16:20:18 +0200
committertranstrike <transtrike@gmail.com>2021-02-13 16:20:18 +0200
commit98e17766b203734a1817eed94338e2d25f4395f7 (patch)
tree1266385a56cba56fd55c7faf661dd844bbdf5705 /src/DevHive.Web/Configurations/Extensions
parent1ab34accfda22ee3ce5c7700e3b97ff3e932d649 (diff)
downloadDevHive-98e17766b203734a1817eed94338e2d25f4395f7.tar
DevHive-98e17766b203734a1817eed94338e2d25f4395f7.tar.gz
DevHive-98e17766b203734a1817eed94338e2d25f4395f7.zip
Project Restructure P.1
Diffstat (limited to 'src/DevHive.Web/Configurations/Extensions')
-rw-r--r--src/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs24
-rw-r--r--src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs70
-rw-r--r--src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs38
-rw-r--r--src/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs16
-rw-r--r--src/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs54
-rw-r--r--src/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs23
6 files changed, 0 insertions, 225 deletions
diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs
deleted file mode 100644
index 8b7d657..0000000
--- a/src/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System;
-using AutoMapper;
-//using AutoMapper.Configuration;
-using Microsoft.AspNetCore.Builder;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace DevHive.Web.Configurations.Extensions
-{
- public static class ConfigureAutoMapper
- {
- public static void AutoMapperConfiguration(this IServiceCollection services)
- {
- services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
- }
-
- public static void UseAutoMapperConfiguration(this IApplicationBuilder app)
- {
- var config = new MapperConfiguration(cfg =>
- {
- cfg.AllowNullCollections = true;
- });
- }
- }
-} \ No newline at end of file
diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs
deleted file mode 100644
index 9f02dd7..0000000
--- a/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.Extensions.Configuration;
-using DevHive.Data.Models;
-using Microsoft.AspNetCore.Identity;
-using Microsoft.AspNetCore.Builder;
-using System;
-using Microsoft.AspNetCore.Authentication.JwtBearer;
-using DevHive.Data;
-
-namespace DevHive.Web.Configurations.Extensions
-{
- public static class DatabaseExtensions
- {
- public static void DatabaseConfiguration(this IServiceCollection services, IConfiguration configuration)
- {
- services.AddDbContext<DevHiveContext>(options =>
- {
- options.EnableSensitiveDataLogging(true);
- options.UseNpgsql(configuration.GetConnectionString("DEV"));
- });
-
- services.AddIdentity<User, Role>()
- .AddRoles<Role>()
- .AddEntityFrameworkStores<DevHiveContext>();
-
- services.Configure<IdentityOptions>(options =>
- {
- options.User.RequireUniqueEmail = true;
-
- options.Password.RequireDigit = true;
- options.Password.RequiredLength = 5;
- options.Password.RequiredUniqueChars = 0;
- options.Password.RequireLowercase = false;
- options.Password.RequireNonAlphanumeric = false;
- options.Password.RequireUppercase = false;
-
- options.Lockout.AllowedForNewUsers = true;
- options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
- options.Lockout.MaxFailedAccessAttempts = 5;
- });
-
- services.AddAuthorization(options =>
- {
- options.AddPolicy("User", options =>
- {
- options.RequireAuthenticatedUser();
- options.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme);
- options.RequireRole("User");
- });
-
- options.AddPolicy("Administrator", options =>
- {
- options.RequireAuthenticatedUser();
- options.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme);
- options.RequireRole("Admin");
- });
- });
- }
-
- public static void UseDatabaseConfiguration(this IApplicationBuilder app)
- {
- app.UseHttpsRedirection();
- app.UseRouting();
-
- app.UseAuthentication();
- app.UseAuthorization();
- }
- }
-}
diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
deleted file mode 100644
index 88f21d4..0000000
--- a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-using DevHive.Data.Interfaces.Repositories;
-using DevHive.Data.Repositories;
-using DevHive.Services.Interfaces;
-using DevHive.Services.Services;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace DevHive.Web.Configurations.Extensions
-{
- public static class ConfigureDependencyInjection
- {
- public static void DependencyInjectionConfiguration(this IServiceCollection services, IConfiguration configuration)
- {
- services.AddTransient<ILanguageRepository, LanguageRepository>();
- services.AddTransient<IRoleRepository, RoleRepository>();
- services.AddTransient<ITechnologyRepository, TechnologyRepository>();
- services.AddTransient<IUserRepository, UserRepository>();
- services.AddTransient<IPostRepository, PostRepository>();
- services.AddTransient<ICommentRepository, CommentRepository>();
- services.AddTransient<IFeedRepository, FeedRepository>();
- services.AddTransient<IRatingRepository, RatingRepository>();
-
- services.AddTransient<ILanguageService, LanguageService>();
- services.AddTransient<IRoleService, RoleService>();
- services.AddTransient<ITechnologyService, TechnologyService>();
- services.AddTransient<IUserService, UserService>();
- services.AddTransient<IPostService, PostService>();
- services.AddTransient<ICommentService, CommentService>();
- services.AddTransient<IFeedService, FeedService>();
- services.AddTransient<ICloudService, CloudinaryService>(options =>
- new CloudinaryService(
- cloudName: configuration.GetSection("Cloud").GetSection("cloudName").Value,
- apiKey: configuration.GetSection("Cloud").GetSection("apiKey").Value,
- apiSecret: configuration.GetSection("Cloud").GetSection("apiSecret").Value));
- services.AddTransient<IRateService, RateService>();
- }
- }
-}
diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs
deleted file mode 100644
index 286727f..0000000
--- a/src/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using DevHive.Web.Middleware;
-using Microsoft.AspNetCore.Builder;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace DevHive.Web.Configurations.Extensions
-{
- public static class ConfigureExceptionHandlerMiddleware
- {
- public static void ExceptionHandlerMiddlewareConfiguration(this IServiceCollection services) { }
-
- public static void UseExceptionHandlerMiddlewareConfiguration(this IApplicationBuilder app)
- {
- app.UseMiddleware<ExceptionMiddleware>();
- }
- }
-}
diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs
deleted file mode 100644
index d422bc8..0000000
--- a/src/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using System.Text;
-using System.Threading.Tasks;
-using DevHive.Services.Options;
-using Microsoft.AspNetCore.Authentication.JwtBearer;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.IdentityModel.Tokens;
-
-namespace DevHive.Web.Configurations.Extensions
-{
- public static class JWTExtensions
- {
- public static void JWTConfiguration(this IServiceCollection services, IConfiguration configuration)
- {
- services.AddSingleton(new JWTOptions(configuration
- .GetSection("AppSettings")
- .GetSection("Secret")
- .Value));
-
- // Get key from appsettings.json
- var key = Encoding.ASCII.GetBytes(configuration
- .GetSection("AppSettings")
- .GetSection("Secret")
- .Value);
-
- // Setup Jwt Authentication
- services.AddAuthentication(x =>
- {
- x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
- x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
- })
- .AddJwtBearer(x =>
- {
- x.Events = new JwtBearerEvents
- {
- OnTokenValidated = context =>
- {
- // TODO: add more authentication
- return Task.CompletedTask;
- }
- };
- x.RequireHttpsMetadata = false;
- x.SaveToken = true;
- x.TokenValidationParameters = new TokenValidationParameters
- {
- //ValidateIssuerSigningKey = false,
- IssuerSigningKey = new SymmetricSecurityKey(key),
- ValidateIssuer = false,
- ValidateAudience = false
- };
- });
- }
- }
-} \ No newline at end of file
diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs
deleted file mode 100644
index a0641ab..0000000
--- a/src/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using Microsoft.AspNetCore.Builder;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.OpenApi.Models;
-
-namespace DevHive.Web.Configurations.Extensions
-{
- public static class SwaggerExtensions
- {
- public static void SwaggerConfiguration(this IServiceCollection services)
- {
- services.AddSwaggerGen(c =>
- {
- c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" });
- });
- }
-
- public static void UseSwaggerConfiguration(this IApplicationBuilder app)
- {
- app.UseSwagger();
- app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"));
- }
- }
-} \ No newline at end of file