2

I have been building a greenfield application. It is three layer (data-access, domain-models, presentation) with the presentation layer being VMVC. This is the cleanest application I've ever built by far, and everything has fallen into place in the architecture very well.

However, there is one fly in my soup aggravating my code OCD... How do I deal with the basic information that is passed around in every page? For example, the name of the currently logged in user, their reputation points, and whatever is in his or her application clipboard. That is to say, how do I get "Top Bar" View-Model passed to common layout view (_Layout.cshtml)?

I have the domain-model user object of the current user referenced in the AppContext object, which has worked well for authorization, ect. But where do I turn that into a view-model and get it to the layout view in a MVC way? Putting that stuff in every single view-model seems a bit ridiculous. Having the AppContext generate the view-model seems... really really dirty.

Sorry if this question is a little petty, but I'd really like to see if you people have some sort of elegant solution that I've missed; especially when the application has come together so cleanly so far.


Clarification of architecture:

Data-Access (Repositories) references domain-model. Presentation references data-access and domain-models. The controller makes a call to the repository which returns the domain-models; these domain-models are mapped to view-models which are then passed to the views.

I am following the one view-model to view rule.

1

Still would be interested in someone else's solution, but here's what I did:

public static class LayoutController
{
    public static LayoutModel Model
    {
        get
        {
            var model = new LayoutModel();
            var user = AppContext.User;
            model.Name = user.PrettyName;
            model.HasSystemAccess = user.HasAccessTo.TheSystem;
            return model;

        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.