ASP.NET MVC application level soft coded settings

半腔热情 提交于 2020-02-06 05:46:22

问题


I am working on a ASP.NET MVC 2.0 Multi-Presentation web application which would use a common codebase to support different websites. These websites would differ in following aspects:

  • Each website will have their own headers, footers, images, CSS etc (I guess website specific Master Pages)
  • Some of the UI elements could be different based on soft-coded settings at website level

What is the best approach to handle these requirements? Should I be storing these website level soft-coded settings in Database or multiple config files? I might have to provide a admin UI to manage these soft-coded settings. How do I access these settings in different layers (MVC, Services, Repositories etc) of my application?

I need suggestions from experts.

Regards, Alex.


回答1:


Develop some sort of Presentation Object Model (or possibly Aggregate if you're DDD inclined) and then persist that to the db. It could be per-user or per-site (if it's a multi-tenanted app you're building) and with MVC it would be easy to build Html Helpers that accept these Presentation Model Objects and render out your customized header, css, images etc.

Potential long-shot practical example:

Let's say your 'tenant' is called a Site - you'll prob have a Site object in your model. A property of Site could be a WebPresentation object. WebPresentation may have a series of child objects and lists with methods for reading css, css files (for <link> elements in the document head), images, etc. You may also have a Service or set of Service functions for persisting/validating the WebPresentation objects (or you may try to have this functionality come off the objects themselves- think .Save()). I won't go into how you persist this data to the db (don't want to insult you). As for the Views, you would design them (perhaps Partial Views) such that the custom WebPresentation Html helpers render the customizations out into the views or <head> sections of your MasterPages.

I hope this example is useful.



来源:https://stackoverflow.com/questions/3878260/asp-net-mvc-application-level-soft-coded-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!