简体   繁体   中英

How to turn on/off code modules?

I am trying to run multiple sites using single code base and code base consist of the following module (ie classes)

  • User module
  • Q & A module
  • Faq module

and each class works on MVC pattern ie it consist of

  • Entity class
  • Helper class (ie static class)
  • View (ie pages and controls)

and let say I have 2 sites site1.com and site2.com . And I am trying to achieve following functionality

  • site1.com can have User, Q & A and Faq module up and running
  • site2.com can have User and Q & A module live while Faq module is switched off but it can be turned-on if needed, so my query here is what is the best way to achieve such functionality

do I introduce a flag bit that I check on every page and control belonging to that module? It's more like CMS where you can turn on/off different features. I am trying to get my head around it, please provide me with an example or point out if I am taking the wrong approach.

You might want to look at Portable areas . You could design the code base so that each module is an area and then deploy them into the sites were they are needed.

After looking to some example and an extensive research I come to a conclusion that it depends upon 2 scenarios:

Scenario 1: If in a case where there is only ten possible modules which are written once and require the whole update of the entire application if they need to be updated, then you can easily use checks which will propagate through the models and be used by the views to adjust the user interface (for example by showing or not the appropriate links in the web application menu).

Scenario 2: If, instead, there is a case of many modules developed by many developers and it is unacceptable to require the update of the whole web application in order to update any of such modules, then look for plugins model, like for example the one used in FogBugz .

For making choice, consider following elements sorted by importance:

  • Maintainability: is it acceptable to modify the common code of the web application in order to change any of the modules?

  • Dependencies: are some modules dependent of others?

  • Performance: since we don't know the exact context, it's difficult to try to predict the impact of each solution. Maybe there will be none, if you use heavy, cleverly designed caching.

  • Overall architecture: if there are reasons to do something monolithic (because of the interdependencies), the first solution seems more appropriate; this is not the case if every module is strictly separated from others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM