In my master layout page, I need to access a SessionManager instance simply to display which user is logged in.
I have it working as follows (_Layout.cshtml):
@using Ninject
@{
var kernel = new StandardKernel();
var sm = kernel.Get<SessionManager>();
}
<!DOCTYPE html>
<html>
...
etc...
Then further down I use the instance like this:
<p>Logged in as @(sm.LoggedInUser.Name)</p>
Now this works, but is this untidy? Can I do this in a better way? Is it OK to create an instance of StandardKernel like this (I assume it's a singleton)?
I thought about making all controllers inherit from a base controller, and injecting the SessionManager into the base controller, but it seems slightly over the top.