How to save changeable parameters in the system?

Asked

Viewed 260 times

5

I have an ASP.NET MVC project and I use web.config to save some parameters that will be used by the system, but should not be changed by any user.

Now I have to implement some other parameters that can be changed by users, without having to restart the application (as happens when a change is made in the web.config). I thought of the following solutions:

  1. Group the parameters by categories and create a table for each of them, placing a record where the columns would have the value of each category parameter, this record could be changed at any time.

But in this case I was a little uncomfortable having in a relational database (Microsoft SQL Server) independent tables with a single record in each. This could be considered a bad practice for evading the concept of relationship?

  1. Create a single table with two columns (varchar in both), one for the parameter name (unique in the table) and the other for the value. This table would play the role of my web.config and I could search the parameters by name.

This solution smells very bad! Because I can’t type the different values of the parameters and may have problems in a possible future migration of the database, or if someone ends up deleting the data.

I thought if there could be any solution, like Nosql for example, generating a file with data in the JSON structure that could store the different types of parameters, and can be changed at any time by users.

In ASP.NET MVC applications there is some option for this problem?

  • 1

    1. I don’t know what you’re considering a bad practice, but it’s a bad idea because each parameter will be a new table. Zero flexibility. 2. If you don’t need the type, there’s no reason to worry about it. If you need the type, this is a bad solution. "3". Nosql is nice, but using an entire database to save half a dozen parameters is a big exaggeration, don’t you think? Especially if you can just save these values in any JSON file. By the way, what’s the problem in creating a simple file?

  • By the way it seems to me that this question would only assume answers based mainly on opinions.

  • Your placements make a lot of sense @LINQ and in fact I can also use a simple file. Thank you so much.

2 answers

5


Group the parameters by categories and create a table for each of them, placing a record where the columns would have the value of each category parameter, this record could be changed at any time.

But in this case I was a little uncomfortable having in a relational database (Microsoft SQL Server) independent tables with a single record in each. This could be considered a bad practice for evading the concept of relationship?

Not every table needs to have a relationship.

Can you tell why it’s bad practice? I can’t do it. It sounds like invention. It seems to be just a taste.

I would prefer not to separate everything into categories, would they in the table itself. But it depends on the case.

Ever thought about keeping a history of the changes? Then each change would be a line. I’m not saying I need it, but it might be more useful than you think.

Create a single table with two columns (varchar in both), one for the parameter name (unique in the table) and one for the value. This table would play the role of my Web.config and I could search the parameters by name.

This solution smells terrible! Because I cannot type the different values of the parameters and I may have problems in a possible future migration of the bank, or if someone ends up deleting the data.

That’s so good there’s even a normal shape indicating to do so.

If you have problems with the guy create a column with him to decide what to do.

Just as you can have a column indicating which category belongs.

If you keep history of changes it may be more interesting to do so.

But to be honest I prefer the former, this is a case that I would adopt if I had certain requirements that in general do not have.

I thought if there could be any solution, like Nosql for example, generating a file with data in the JSON structure that could store the different types of parameters, and can be changed at any time by users.

Using another Nosql database just for that? for me is a terrible solution.

Why do you need JSON? I see no reason. For categories? In most cases these parameters could be flat.

Current versions of SQL Server support JSON natively. The old ones can use a VARCHAR to store JSON, it only takes a little more work.

Other solutions

You can put it in a file too, no matter the format. I prefer inside the database, but I see no reason why this would work worse than DB unless it has some restriction of access to the files directly.

In thesis you can even continue using the web.config and have it read to make the modifications in the application. It is possible to control whether or not the application restarts.

It may be that not all requirements have been informed. There may be a reason not to use one of the solutions cited.

2

I propose the solution "4":

Use the Database that is already in the application, create a table with all parameters, with name and value, and in the value field, as is String, you can use objects in JSON format as well, if you need to.

If you need to know the type, add another field for this and, in the routine that reads the parameters, interpret this field and parse the string for the desired type.

In case of missing parameter, consider assuming a default value if you do not find the field in the table or it is invalid.

I may have problems with a possible future bank migration, or if someone ends up deleting the data

You would also have problems if someone ended up deleting data from users, customers, sales... so this is not a reason against this approach.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.