aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Startup.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline/Startup.cs')
-rw-r--r--Timeline/Startup.cs24
1 files changed, 17 insertions, 7 deletions
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs
index 88348892..87de7501 100644
--- a/Timeline/Startup.cs
+++ b/Timeline/Startup.cs
@@ -1,16 +1,18 @@
+using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SpaServices.AngularCli;
+using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using System.Text;
using Timeline.Configs;
-using Timeline.Services;
-using Microsoft.AspNetCore.HttpOverrides;
using Timeline.Formatters;
+using Timeline.Models;
+using Timeline.Services;
namespace Timeline
{
@@ -37,8 +39,8 @@ namespace Timeline
configuration.RootPath = "ClientApp/dist";
});
- services.Configure<JwtConfig>(Configuration.GetSection("JwtConfig"));
- var jwtConfig = Configuration.GetSection("JwtConfig").Get<JwtConfig>();
+ services.Configure<JwtConfig>(Configuration.GetSection(nameof(JwtConfig)));
+ var jwtConfig = Configuration.GetSection(nameof(JwtConfig)).Get<JwtConfig>();
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(o =>
@@ -52,8 +54,16 @@ namespace Timeline
o.TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtConfig.SigningKey));
});
- services.AddSingleton<IUserService, UserService>();
- services.AddSingleton<IJwtService, JwtService>();
+ services.AddScoped<IUserService, UserService>();
+ services.AddScoped<IJwtService, JwtService>();
+ services.AddTransient<IPasswordService, PasswordService>();
+
+ var databaseConfig = Configuration.GetSection(nameof(DatabaseConfig)).Get<DatabaseConfig>();
+
+ services.AddDbContext<DatabaseContext>(options =>
+ {
+ options.UseMySql(databaseConfig.ConnectionString);
+ });
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.