I have a netstandard 2.0 Class library, which for some functionality needs dependency injection. I need to have the following method called in my library:
public static class HttpContext
{
/// <summary>
/// Returns the current httpContext
/// </summary>
public static Microsoft.AspNetCore.Http.HttpContext Current => _httpContextAccessor?.HttpContext;
private static Microsoft.AspNetCore.Http.IHttpContextAccessor _httpContextAccessor;
/// <summary>
/// Call this in Configure in Startup.cs, to configure the HttpContext.Current.
/// Don't forget to also add 'services.AddHttpContextAccessor();' to ConfigureServices
/// </summary>
/// <param name="app"></param>
public static void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app)
{
_httpContextAccessor = app.ApplicationServices.GetRequiredService<Microsoft.AspNetCore.Http.IHttpContextAccessor>();
}
}
(Now I know this is a crutch, to get to the HttpContext, but in converting my library to netstandard, this was the best way. Of course I'm happy to listen to another suggestion on how to get httpcontext code useable in .netframework en .netstandard)
I've been searching and searching, but I haven't been able to find how to get this working. Is this at all possible? Because from what I have been finding, I get the impression it is not supported
Remco