当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Better approach to store configuration settings - in-memory or database

问题描述:

I am working on a simple C# windows application, I've some standard reports and their parameters, along with configuration settings that remain constant in the application. So, I'm thinking which is the better approach to store these values.

If it is database design I can imagine through below tables

Report: Id, Name

ReportParameters: Id, Name, ReportId

Configuration: Id, Name, Value, Environment

Report contains 5 records, and each report contains max 3 parameters and configuration contains 5 records for each environment.

For these kind of scenarios, would it be advisable to store in database or in-memory variables.

Edit

This windows application will be used every quarter, so IMO database + cache doesn't seem to be good idea.

网友答案:

I would probably do something via appSettings then since you aren't storing too much. You could also create a custom object, serialize it and then deserialize it when you need it. There are lots of different options but those are probably the first ones I would consider in your case.

网友答案:

If it's in-memory, then all of your configuration will be lost every time you close the program. Based on:

Report contains 5 records, and each report contains max 3 parameters and configuration contains 5 records for each environment.

it seems like a very minimal number of settings. I would serialize some object to an XML file.

网友答案:

Unless you are already using a database, I'd plan on just serializing the settings. If you are using a database, this might make sense, particularly if the settings change often. That makes it easy to just poke the database and change the settings. Similarly if you serialize in XML.

Keeping them in the source code should be a last resort, since any report settings are likely to change or be added. You shouldn't have to recompile the code to add a new report.

分享给朋友:
您可能感兴趣的文章:
随机阅读: