Is it okay to use injection when writing code for a simple settings class?
I have some class like Simulator
, which has it's own SimulatorSettings
. So what approach should I take to inject these settings using something 开发者_JS百科like ninject
?
Or maybe my approach is incorrect and I should do something other about this kind of settings?
Your question is not very clear - if I understand correctly, you are asking if you should be using Dependency Injection and an IoC container (such as ninject) in order to inject a settings object into your class.
This is perfectly fine, though you should probably consider using a factory for constructing your objects instead (in particular the settings object would to be initialized correctly).
When you are talking about configuration sections you could do something like:
this.Bind<SimulatorSettings>().ToMethod(
ctx => (SimulatorSettings) ConfigurationManager.GetSection["Simulator"])
Have fun
精彩评论