Hello @Amr_Ali
If the following is not what you care for then please provide more details.
In regards to using XML, yes this is possible so long as you can write code in the application that can follow settings in the XML but another idea is to use a Json file instead as using Json when setup to read everything is strongly typed while XML is not.
I have an example which controls unseen operations, in this case to log information to a log file. Below Helper class reads information from a Json file using Json.Net library into an instance of a class then in code we can ask for UsingLogging.
JSON
{
"GeneralSettings": {
"LogExceptions": false,
"DatabaseSettings": {
"DatabaseServer": ".\\SQLEXPRESS",
"Catalog": "NorthWind2020",
"IntegratedSecurity": true,
"UsingLogging": true
},
"EmailSettings": {
"Host": "smtp.gmail.com",
"Port": 587,
"EnableSsl": true,
"DefaultCredentials": false,
"PickupDirectoryLocation": "MailDrop"
}
}
}
Code
Protected Overrides Sub OnConfiguring(ByVal optionsBuilder As DbContextOptionsBuilder)
If Not optionsBuilder.IsConfigured Then
If Helper.UseLogging() Then
optionsBuilder.UseSqlServer(Helper.ConnectionString()).EnableSensitiveDataLogging().EnableDetailedErrors().LogTo(_logStream.WriteLine)
Else
optionsBuilder.UseSqlServer(Helper.ConnectionString())
End If
End If
End Sub
- Classes to store information are found here in my GitHub repository.
- The following class (also in the same repository) provides code to read the json file above with a small example to write back to the json file.
- Since the class in the last bullet uses shared methods it's easy to obtain information any place in your code to respond to and get changes in code logic where the settings may change in a admin form.
- The Admin form reads and changes settings
- No matter if there are changes or just reading, at application startup you can read settings into a singleton class or a code module and other parts of the code can use what was read at startup.
Control changes
The following is from the second bullet above which indicates how to read and respond to if changes are made at runtime to the underlying json file.
Below shows a class project (found here) which is portable to any project for reading json
The following is an example (has no ties to the code above other than it uses the exact same logic mention above) where the top form is accessed from the "Misc" menu, user makes changes and then when actions are performed they use setting from the json file.
Redirecting assembly versions
Even though the following may not suit your needs it is at least worth knowing about which does need a update installation is working with versions of a DLL which explained here.
Part of the solution is to update the .config file .e.g.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="en-us" />
<bindingRedirect oldVersion="1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>