Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use HttpContext as a field #12005

Merged
merged 2 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ namespace OrchardCore.DisplayManagement.ModelBinding
public class LocalModelBinderAccessor : IUpdateModelAccessor
{
private readonly static object Key = typeof(LocalModelBinderAccessor);
private readonly HttpContext _httpContext;
private readonly IHttpContextAccessor _httpContextAccessor;

public LocalModelBinderAccessor(IHttpContextAccessor httpContextAccessor)
{
_httpContext = httpContextAccessor.HttpContext;
_httpContextAccessor = httpContextAccessor;
}

public IUpdateModel ModelUpdater
{
get
{
var updateModel = _httpContext.Items[Key] as IUpdateModel;
var updateModel = _httpContextAccessor.HttpContext.Items[Key] as IUpdateModel;
return updateModel ?? new NullModelUpdater();
}

set { _httpContext.Items[Key] = value; }
set { _httpContextAccessor.HttpContext.Items[Key] = value; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class IpAddressRobotDetector : IDetectRobots
private const string IpAddressAbuseDetectorCacheKey = "IpAddressRobotDetector";

private readonly IMemoryCache _memoryCache;
private readonly HttpContext _httpContext;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ReCaptchaSettings _settings;

public IpAddressRobotDetector(IHttpContextAccessor httpContextAccessor, IMemoryCache memoryCache, IOptions<ReCaptchaSettings> settingsAccessor)
{
_httpContext = httpContextAccessor.HttpContext;
_httpContextAccessor = httpContextAccessor;
_memoryCache = memoryCache;
_settings = settingsAccessor.Value;
}
Expand All @@ -33,7 +33,7 @@ private string GetIpAddressCacheKey()

private string GetIpAddress()
{
return _httpContext.Connection.RemoteIpAddress.ToString();
return _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
}

public RobotDetectionResult DetectRobot()
Expand Down