如问题,由于静态类不是IHttpContextAccessor和HttpContext属性,如何解决它?
public static class IPHelper
{
//this is a wrong define
private readonly IHttpContextAccessor _accessor;
public string GetRemoteIP()
{
return _accessor.HttpContext.Connection.RemoteIpAddress?.ToString();
}
}上面,_accessor不能在静态类中定义而不能构造。怎么注射?
发布于 2022-06-18 13:07:36
使用abstract关键字而不是static。
https://stackoverflow.com/questions/42946703
复制相似问题