aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Startup.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline/Startup.cs')
-rw-r--r--Timeline/Startup.cs33
1 files changed, 27 insertions, 6 deletions
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs
index 8e8a6393..b44add6f 100644
--- a/Timeline/Startup.cs
+++ b/Timeline/Startup.cs
@@ -2,10 +2,13 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
+using Microsoft.AspNetCore.Localization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
-using Timeline.Authenticate;
+using System.Collections.Generic;
+using System.Globalization;
+using Timeline.Authentication;
using Timeline.Configs;
using Timeline.Entities;
using Timeline.Helpers;
@@ -13,6 +16,7 @@ using Timeline.Services;
namespace Timeline
{
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static")]
public class Startup
{
public Startup(IConfiguration configuration, IWebHostEnvironment environment)
@@ -27,11 +31,12 @@ namespace Timeline
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
- services.AddMvc()
+ services.AddControllers()
.ConfigureApiBehaviorOptions(options =>
{
options.InvalidModelStateResponseFactory = InvalidModelResponseFactory.Factory;
- });
+ })
+ .AddNewtonsoftJson();
services.Configure<JwtConfig>(Configuration.GetSection(nameof(JwtConfig)));
var jwtConfig = Configuration.GetSection(nameof(JwtConfig)).Get<JwtConfig>();
@@ -48,13 +53,17 @@ namespace Timeline
);
});
+ services.AddLocalization(options =>
+ {
+ options.ResourcesPath = "Resources";
+ });
+
services.AddScoped<IUserService, UserService>();
services.AddScoped<IJwtService, JwtService>();
services.AddTransient<IPasswordService, PasswordService>();
services.AddTransient<IClock, Clock>();
services.AddUserAvatarService();
- services.AddUserDetailService();
var databaseConfig = Configuration.GetSection(nameof(DatabaseConfig)).Get<DatabaseConfig>();
@@ -63,11 +72,10 @@ namespace Timeline
options.UseMySql(databaseConfig.ConnectionString);
});
- services.AddHttpClient();
-
services.AddMemoryCache();
}
+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
@@ -78,6 +86,19 @@ 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();