开发者

Approaches for Application Configuration and Settings (in ASP.NET MVC)

For a CMS product/platform, what would be a maintainable and clear approach for editing and storing settings?

I'm not talking about technical (connstring, nh config, ...) settings, but settings that alter the behaviour of the product:

These settings are for example

  • Online Payment settings
  • Available parts and modules
  • Default behaviour of the application (showing details of list items by default, default landing page after certain actions)
  • ...

At this point we don't really have an approach, so the result is that all settings end up in the web.config.

This is probably not the best approach, since this is simply ending in an endless list of obscure key value pairs...

In this scenario we also cannot really anticipate to types (without codegen), so settings with checkboxes or predefined options... are hard to manage.

Another option would be to create the needed tables for each setting (type) and use that as a core setting system, but this will be harder to deploy and manage per customer.

I have lots of half answers to this question but not really a top down solution...

What I mean by top down:

  • Editing settings (admin screen)
  • Where to persist the settings
  • Loading the settings, without much hassle, but still in a maintainable way
  • Maintain/deploy customer specific settings

So options so far:

  • (web).config
  • .settings files
  • DB

But these are all kind of key-value appro开发者_C百科aches... Any other suggestions?


You could write a custom configuration section which allows you to store much more than key/value settings in the config file. This being said the config file is designed for read-only settings. If you need editing functionalities with admin screens then it would be best to use database. Storing this information in files is also a possibility but as this is a multi-threaded application you will need to properly synchronize access to those files which could quickly become cumbersome.


Basicly you can create Setting table. includes Name and Value fields. And you can store setting.

public class Setting : Entity
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Value { get; set; }
}

There will be a lot of rows for setting in table. This structure is basicly key-value pair usage. But! My advice use structure below.

public class Setting : Entity
{
    public int Id { get; set; }
    public string SiteName { get; set; }
    public string ProductsPerPage { get; set; }
    ...
}

Because, it will be easy to caching. You can fetch all Setting table and just cache it. Easy caching and no more queries.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜