I don’t know if this is something that can be handled by a DI since I am still wrapping my head around using a DI.
Project:
I have an object of ISettings that I want to hand off to a ISettingsVerification class. However, I have a number of different classes that inherit from ISettingsVerification. These classes all handle the ISettings object differently based on a particular property (IisVersion).
Question:
How can I set it up so that in the main program, I don’t worry about which ISettingsVerification class gets the ISettings Object, that my program will handle that logic. I am familiar with using the DI Ninject, would this be something that I could do there, or am I going to have to use something like a Switch statement to make that determination?
I like the idea of extracting this logic from the heart of my application.
Thanks
You’ll probably have to write a switch statement somewhere. But of course it doesn’t have to be in the “heart of the application”.
One solution would be to use some kind of factory:
Now you can use that factory (through injection or directly) when you need a verifier for a settings object.