Loading custom configuration files
the articles posted by Ricky are very good, but unfortunately they don't answer your question.
To solve your problem you should try this piece of code:
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
configMap.ExeConfigFilename = @"d:\test\justAConfigFile.config.whateverYouLikeExtension";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
If need to access a value within the config you can use the index operator:
config.AppSettings.Settings["test"].Value;
How to load a custom config file in a Bundleless application with Treebuilder?
Seems like I saw a similar question a few months ago but can't find it. The src/Kernel class acts as a AppBundle class and allows you to do things like register extensions.
# src/Kernel.php
class Kernel extends BaseKernel
{
use MicroKernelTrait;
protected function prepareContainer(ContainerBuilder $container)
{
$container->registerExtension(new TestExtension());
parent::prepareContainer($container);
}
...
# src/TestExtension.php
class TestExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
// TODO: Implement load() method.
dump($configs);
}
}
As far as processing a tree builder without an extension, I don't know if that is possible. The config stuff is already complicated enough so I would not go there myself.
Bit off-topic, I could not find an actual documented case of using prepareContainer in Kernel. The source code makes it clear that the approach shown above will work.
Most of the time app specific configurations are just done in the config directory. The main point of the bundle configuration system is to allow the app to override default bundle configurations. I'm not really seeing the point of an app level extension. What would override it? Maybe some sort of sophisticated database driven tree builder? Seems unlikely.
This could be a case of just because you can do something does not mean you should.
How to load a custom .config file with Configuration
In your type
property, you have to tell it which assembly contains your Tedski.Configuration.TedskiSection
. For example:
<section name="Tedski" type="Tedski.Configuration.TedskiSection, TedskiAssemblyName" />
Replace "TedskiAssemblyName" there with the name of the assembly that contains the class.
Symfony 2 loading custom configuration file
Well, I have not tried it but you should be able to use the Yaml extension to load in the canonisers.yml file directly and add it to configs. Not recommended (bypasses the application caching stuff) but it might work:
use Symfony\Component\Yaml\Yaml;
class MailbrokerMailDetailsExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$file = __DIR__.'/../Resources/config/canonisers.yml';
$configs = array_merge($configs,Yaml::parse(file_get_contents($file));
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
....
Completely untested. You might need to add to app/config/config.yml
mailbroker_mail_details: ~
Just to get past the error message. Not sure.
Let me know if it works.
Read custom config file using custom config classes?
Here's what I ended up doing:
var map = new ExeConfigurationFileMap();
map.ExeConfigFilename = @"C:\Users\sirdank\project\bootstrapper\bin\Debug\test.config";
System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
DatabaseConfig dbConfig = config.GetSection("DatabaseConfigSection") as DatabaseConfig;
Put together with the help of MSDN
Load custom configuration runtime
If someone else has this kind of problem here is the solution I came up with in the end:
// plugins/config.js
class Settings
{
constructor (app, req) {
if (process.server) {
// Server side we load the file simply by using fs
const fs = require('fs');
this.json = fs.readFileSync('config.json');
} else {
// Client side we make a request to the server
fetch('/config')
.then((response) => {
if (response.ok) {
return response.json();
}
})
.then((json) => {
this.json = json;
});
}
}
}
export default function ({ req, app }, inject) {
inject('config', new Settings(app, req));
};
For this to work we need to use a server middleware:
// api/config.js
const fs = require('fs');
const express = require('express');
const app = express();
// Here we pick up requests to /config and reads and return the
// contents of the configuration file
app.get('/', (req, res) => {
fs.readFile('config.json', (err, contents) => {
if (err) {
throw err;
}
res.set('Content-Type', 'application/json');
res.end(contents);
});
});
module.exports = {
path: '/config',
handler: app
};
Related Topics
How to Protect My .Net Assemblies from Decompilation
How to Get the Current User in ASP.NET MVC
How Might I Schedule a C# Windows Service to Perform a Task Daily
Xml Serialization - Hide Null Values
{"<User Xmlns=''> Was Not Expected.} Deserializing Twitter Xml
How to Make Sure That String Is Valid JSON Using JSON.Net
Find Number of Decimal Places in Decimal Value Regardless of Culture
C# List of Objects, How to Get the Sum of a Property
How to Pass a Value from a Child Back to the Parent Form
Run Single Instance of an Application Using Mutex
How to Detect If Console.In (Stdin) Has Been Redirected
Linq - Left Join, Group By, and Count
Deep Null Checking, Is There a Better Way