I appologize if this is a possible duplication, I've looked everywhere and couldn't find an answer.
My question is more of a "best practice/convention"-sort of question.
So here is my situation, I'm having an AccountController -> something like this:
public AccountController(IAuthenticationHelper authHelper,
IAccountService accountService)
{
_authHelper = authHelper;
_accountService = accountService;
}
In my _Layout view, I have a placeholder for the currently logged in account. In order to get the currently logged in account, I'm retrieving the current user identity from the HttpContext (which I have in a wrapper class so I can unit test it) -> then I'm getting the account details from the DB.
Now here is my question, I need this data In the _Layout, I could possibly do a partial view expecting an account model -> place it in the _Layout ... And here is where I get stuck, I don't like the idea of so many trips to the database, and I don't like the fact that I have to think about this small detail from within all Actions ? Am I missing something here, am I thinking of this wrong ? Did I got the concept wrong ? What's the right way to do this ? (In a testable manner, preferably).
Help is much appreciated !
EDIT: I'll be happy to provide with more code, if required.
BaseController.