diff options
author | 杨宇千 <crupest@outlook.com> | 2020-02-01 00:26:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-01 00:26:35 +0800 |
commit | 7b962cd876719fb871569ba3c97fb5545721a3f8 (patch) | |
tree | f02f8d57440c777d4732bc4439f82e8b25c6732c /Timeline/Startup.cs | |
parent | 289c7e1fada1f4dae6ce5e421e997ebddd55c2df (diff) | |
parent | bcb0a2361467614531a337282da1fd23996924f1 (diff) | |
download | timeline-7b962cd876719fb871569ba3c97fb5545721a3f8.tar.gz timeline-7b962cd876719fb871569ba3c97fb5545721a3f8.tar.bz2 timeline-7b962cd876719fb871569ba3c97fb5545721a3f8.zip |
Merge pull request #56 from crupest/dev
Refactor API to be RESTful.
Diffstat (limited to 'Timeline/Startup.cs')
-rw-r--r-- | Timeline/Startup.cs | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs index 5b6499a4..86349a27 100644 --- a/Timeline/Startup.cs +++ b/Timeline/Startup.cs @@ -1,14 +1,16 @@ +using AutoMapper;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
-using Microsoft.AspNetCore.Localization;
+using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
+using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
+using Pomelo.EntityFrameworkCore.MySql.Storage;
using System;
-using System.Collections.Generic;
-using System.Globalization;
using System.Text.Json.Serialization;
using Timeline.Auth;
using Timeline.Configs;
@@ -50,7 +52,6 @@ namespace Timeline });
services.Configure<JwtConfig>(Configuration.GetSection(nameof(JwtConfig)));
- var jwtConfig = Configuration.GetSection(nameof(JwtConfig)).Get<JwtConfig>();
services.AddAuthentication(AuthenticationConstants.Scheme)
.AddScheme<MyAuthenticationOptions, MyAuthenticationHandler>(AuthenticationConstants.Scheme, AuthenticationConstants.DisplayName, o => { });
services.AddAuthorization();
@@ -78,20 +79,20 @@ namespace Timeline });
}
- services.AddLocalization(options =>
- {
- options.ResourcesPath = "Resources";
- });
+ services.AddAutoMapper(GetType().Assembly);
- services.AddScoped<IUserService, UserService>();
- services.AddScoped<IJwtService, JwtService>();
- services.AddTransient<IPasswordService, PasswordService>();
services.AddTransient<IClock, Clock>();
+
+ services.AddTransient<IPasswordService, PasswordService>();
+ services.AddScoped<IUserService, UserService>();
+ services.AddScoped<IUserTokenService, JwtUserTokenService>();
+ services.AddScoped<IUserTokenManager, UserTokenManager>();
services.AddUserAvatarService();
- services.AddScoped<IUserDetailService, UserDetailService>();
services.AddScoped<IPersonalTimelineService, PersonalTimelineService>();
+ services.TryAddSingleton<IActionContextAccessor, ActionContextAccessor>();
+
var databaseConfig = Configuration.GetSection(nameof(DatabaseConfig)).Get<DatabaseConfig>();
if (databaseConfig.UseDevelopment)
@@ -109,11 +110,10 @@ namespace Timeline {
if (databaseConfig.ConnectionString == null)
throw new InvalidOperationException("DatabaseConfig.ConnectionString is not set. Please set it as a mysql connection string.");
- options.UseMySql(databaseConfig.ConnectionString);
+ options.UseMySql(databaseConfig.ConnectionString,
+ mySqlOptions => mySqlOptions.ServerVersion(new ServerVersion(new Version(5, 7), ServerType.MySql)));
});
}
-
- services.AddMemoryCache();
}
@@ -127,19 +127,6 @@ namespace Timeline app.UseRouting();
- var supportedCultures = new List<CultureInfo>
- {
- new CultureInfo("en"),
- new CultureInfo("zh")
- };
-
- app.UseRequestLocalization(new RequestLocalizationOptions
- {
- DefaultRequestCulture = new RequestCulture("en"),
- SupportedCultures = supportedCultures,
- SupportedUICultures = supportedCultures
- });
-
app.UseCors();
app.UseAuthentication();
|