You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.2 KiB
84 lines
2.2 KiB
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Serilog;
|
|
using System;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using Wood.Util.JwtAuthorization;
|
|
|
|
namespace Wood.Util
|
|
{
|
|
public class GlobalContext
|
|
{
|
|
/// <summary>
|
|
/// All registered service and class instance container. Which are used for dependency injection.
|
|
/// </summary>
|
|
public static IServiceCollection? Services { get; set; }
|
|
|
|
/// <summary>
|
|
/// Configured service provider.
|
|
/// </summary>
|
|
public static IServiceProvider? ServiceProvider { get; set; }
|
|
/// <summary>
|
|
/// Configuration
|
|
/// </summary>
|
|
public static IConfiguration? Configuration { get; set; }
|
|
/// <summary>
|
|
/// HostingEnvironment
|
|
/// </summary>
|
|
public static IWebHostEnvironment? HostingEnvironment { get; set; }
|
|
|
|
/// <summary>
|
|
/// 自定义系统配置信息
|
|
/// </summary>
|
|
public static SystemConfig? SystemConfig { get; set; }
|
|
/// <summary>
|
|
/// JWT权限验证信息
|
|
/// </summary>
|
|
public static JwtConfig? JwtConfig { get; set; }
|
|
|
|
/// <summary>
|
|
/// 获取配置信息
|
|
/// </summary>
|
|
/// <param name="path">配置路径</param>
|
|
/// <returns></returns>
|
|
public static string? GetConfig(string path)
|
|
{
|
|
return Configuration![path]?.ToString();
|
|
}
|
|
/// <summary>
|
|
/// 用户信息
|
|
/// </summary>
|
|
public static JwtUserInfo? UserInfo
|
|
{
|
|
get
|
|
{
|
|
var httpContextAccessor = ServiceProvider?.GetRequiredService<IHttpContextAccessor>();
|
|
return httpContextAccessor?.UserInfo();
|
|
}
|
|
}
|
|
public static string GetVersion()
|
|
{
|
|
Version version = Assembly.GetEntryAssembly()!.GetName().Version!;
|
|
return version.Major + "." + version.Minor;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 程序启动时,记录目录
|
|
/// </summary>
|
|
/// <param name="env"></param>
|
|
public static void LogWhenStart(IWebHostEnvironment env)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append("程序启动");
|
|
sb.Append(" |ContentRootPath:" + env.ContentRootPath);
|
|
sb.Append(" |WebRootPath:" + env.WebRootPath);
|
|
sb.Append(" |IsDevelopment:" + env.IsDevelopment());
|
|
Log.Debug(sb.ToString());
|
|
}
|
|
}
|
|
}
|
|
|