简体   繁体   English

如何打开/关闭代码模块?

[英]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 每个类都适用于MVC模式,即它由

  • Entity class 实体类
  • Helper class (ie static class) 助手类(即静态类)
  • View (ie pages and controls) 查看(即页面和控件)

and let say I have 2 sites site1.com and site2.com . 假设我有2个站点site1.comsite2.com And I am trying to achieve following functionality 我正在努力实现以下功能

  • site1.com can have User, Q & A and Faq module up and running site1.com可以启动并运行User,Q&A和Faq模块
  • 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 在关闭Faq模块时,site2.com可以有用户和Q&A模块,但如果需要可以打开它,所以我的查询是什么是实现这种功能的最佳方式

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. 它更像CMS,你可以打开/关闭不同的功能。 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). 场景1:如果只有十个可能的模块被写入一次并且需要整个更新整个应用程序需要更新,那么您可以轻松地使用将通过模型传播并由用于调整用户界面的视图(例如,通过显示或不显示Web应用程序菜单中的相应链接)。

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 . 场景2:相反,如果有许多开发人员开发了许多模块,并且要求更新整个Web应用程序以更新任何此类模块是不可接受的,那么请查找插件模型,例如一个在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? 可维护性:修改Web应用程序的公共代码以更改任何模块是否可以接受?

  • 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. 如果每个模块都与其他模块严格分开,则情况并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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