asp.net mvc 3 - Mvc3 - Best practice to deal with data which are required for (almost) all requests? -


i creating application in mvc3 , wondering how deal database data required application requests, of them depends on session, of them depends on url pattern data in database.

like know best practice

what in applications , consider best practice load common data viewbag on controller constructor.

for every project, have defaultcontroller abstract class extends controller. so, every controller in project must inherit defaultcontroller, instead of controller. in class' constructor, load data common whole project, so:

// defaultcontroller.cs public abstract class defaultcontroller : controller {     protected irepository repo { get; private set; }      protected defaultcontroller(irepository repo)     {         repo = repo;         viewbag.currentuser = getloggedinuser();     }      protected user getloggedinuser()     {         // logic retrieving data here     } }   // homecontroller.cs public class homecontroller : defaultcontroller {     public homecontroller(irepository repo) : base(repo)     {     }      // ... action methods } 

that way have logged in user available in views.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -