using System;
using System.Diagnostics;
#if NET || NETCOREAPP
using Microsoft.AspNetCore.Http;
#else
using System.Web;
#endif
namespace CNet.DBUtility
{
///
/// Temporary helper class for retrieving the current . This temporary
/// workaround should be removed in the future and should be retrieved
/// from the current controller, middleware, or page instead.
#if NET || NETCOREAPP
///
/// If working in another component, the current can be retrieved from an
/// retrieved via dependency injection.
#endif
///
internal static class HttpContextHelper
{
private const string Message = "Prefer accessing HttpContext via injection";
///
/// Gets the current . Returns null if there is no current .
///
#if NET || NETCOREAPP
#if NET5_0_OR_GREATER
[Obsolete(Message, error: false, DiagnosticId = "HttpContextCurrent", UrlFormat = "https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-context")]
#else
[Obsolete(Message, error: false)]
#endif
public static HttpContext Current => HttpContextAccessor.HttpContext;
private static readonly HttpContextAccessor HttpContextAccessor = new HttpContextAccessor();
#else
#pragma warning disable UA0005 // Do not use HttpContext.Current
[Obsolete(Message, error: false)]
public static HttpContext Current => HttpContext.Current;
#pragma warning restore UA0005 // Do not use HttpContext.Current
#endif
}
}