ASP.Net 5 (MVC 6) - Accessing session object in view via a wrapper
<p>I have a class</p>

<pre><code>public class SessionService : ISessionService
{
    public const string SessionUserKey = "UserViewModel";

    private readonly IHttpContextAccessor _httpContextAccessor;

    private ISession _session =&gt; _httpContextAccessor.HttpContext.Session;

    public SessionService(IHttpContextAccessor httpContextAccessor)
    {
        _httpContextAccessor = httpContextAccessor;
    }

    public UserViewModel LoggedInUser
    {
        get
        {
            return _session.GetObjectFromJson&lt;UserViewModel&gt;(SessionUserKey);
        }
        set
        {
            _session.SetObjectAsJson(SessionUserKey, value);
        }
    }

    public void Destroy()
    {
        _session.Clear();
    }
}
</code></pre>

<p>An instance of this class is injected to my controller like this:</p>

<p>Startup.cs</p>

<pre><code>services.AddScoped&lt;ISessionService, SessionService&gt;();
</code></pre>

<p>AccountController.cs</p>

<pre><code>public class AccountController : Controller
{
    private readonly IUserAccountService _accountService;
    private readonly ISessionService _sessionService;

    public AccountController(IUserAccountService accountService, ISessionService sessionService)
    {
        _accountService = accountService;
        _sessionService = sessionService;
    }
}
</code></pre>

<p>However, in my view I want to access the currently logged in user like this:</p>

<pre><code> @if(SomeClass.LoggedInUser != null){
 // code removed for brevity
 }
</code></pre>

<p>How can I achieve this without making the <code>LoggedInUser</code> property of my <code>SessionService</code> class static. It seems like something needs to me made static to have an access like this. But I was wondering if there was a better way to accomplish this. And no, I don't want to use the <code>ViewBag</code>.</p>

<p><strong>I am not using ASP.Net Identity</strong></p>