I have some devices and some modules in my app that use devices to make their job.
There are two approaches for configuration structure:
Approach 1:
<device1>
<configurationForModule1 />
<configurationForModule2 />
</device1>
<device2>
<configurationForModule1 />
<configurationForModule2 />
</device2>
Then using looks like the following sample:
public class Module1 {
private readonly _device1;
public Module1(Device1 device1) {
_device1 = device1;
// configuration for this module in _device1.Configuration.Module1
}
}
Approach 2:
<configurationForModule1>
<device1 />
<device2 />
</configurationForModule1>
<configurationForModule2>
<device1 />
<device2 />
</configurationForModule2>
Then using looks like the following sample:
public class Module1 {
private readonly _device1;
public Module1(Module1Configuration configuration, Device1 device1) {
_device1 = device1;
// configuration for this module in configuration.Device1
}
}
In addition:
Modules can solve issues like:
How should I structure the configuration?
From your explanation it looks like the main entities for your project are modules, and the purpose of devices is to allow the modules to do their work. If that's true, then approach 2 seems to be the most logical one.
Additionally, the second approach allows you to easily supply module configuration that is not directly related to devices (stuff like e.g. database connections, location of resources, or logging); with approach 1 you would have to replicate this information for each device.