Skip to content

Commit

Permalink
fix(src/plugincore.aspnetcore/middlewares/languagemiddleware.cs): nam…
Browse files Browse the repository at this point in the history
…espace: 语法降级
  • Loading branch information
yiyungent committed Dec 29, 2023
1 parent d438fad commit a1f83fc
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/PluginCore.AspNetCore/Middlewares/LanguageMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,35 @@
using Microsoft.AspNetCore.Http;
using PluginCore.IPlugins;

namespace PluginCore.AspNetCore.Middlewares;

public class LanguageMiddleware
namespace PluginCore.AspNetCore.Middlewares
{
private readonly RequestDelegate _next;

public LanguageMiddleware(RequestDelegate next)
public class LanguageMiddleware
{
_next = next;
}
private readonly RequestDelegate _next;

public async Task Invoke(HttpContext httpContext)
{
// 从 Cookie 中获取语言标识
string language = httpContext.Request.Cookies[Constants.AspNetCoreLanguageCookieName];
public LanguageMiddleware(RequestDelegate next)
{
_next = next;
}

// 存储当前语言到 HttpContext.Items
httpContext.Items[Constants.AspNetCoreLanguageKey] = language;
public async Task Invoke(HttpContext httpContext)
{
// 从 Cookie 中获取语言标识
string language = httpContext.Request.Cookies[Constants.AspNetCoreLanguageCookieName];

// 调用下一个中间件
await _next(httpContext);
// 存储当前语言到 HttpContext.Items
httpContext.Items[Constants.AspNetCoreLanguageKey] = language;

// 调用下一个中间件
await _next(httpContext);
}
}
}

public static class LanguageMiddlewareExtensions
{
public static IApplicationBuilder UseLanguageMiddleware(this IApplicationBuilder builder)
public static class LanguageMiddlewareExtensions
{
return builder.UseMiddleware<LanguageMiddleware>();
public static IApplicationBuilder UseLanguageMiddleware(this IApplicationBuilder builder)
{
return builder.UseMiddleware<LanguageMiddleware>();
}
}
}

0 comments on commit a1f83fc

Please sign in to comment.