2

I have a feeling that this has been answered several times before, I just don't have the experience to know how to search for the answer. So, I apologize ahead of time for the stupid question.

Here it goes, I am using Caliburn.Micro and am thinking about employing some sort of IoC Container to reap the benefits of Dependency Injection. I have a view that's sole purpose is to change the app's configuration settings. If any changes are saved by the user, I use an EventAggregator to post the settings to a configuration file manager. The configuration file manager makes the changes, saves them to file, and then publishes all the settings via the Event Aggregator. One such setting is the ComPort and Baud Rate of a serial port connection to a Radio.

Now for dependency injection. As far as I know, you setup your bindings in the Bootstrapper and it is configured when the app starts. How can I change this dynamically so that RadioReader(newComPort, newBaudRate) is always returned when requested. Further, I have a requirement to give the user an option to talk to the radio via a UDP Port. So, I want to make an IRadioReader interface to allow the user to dynamically change the transport as well as the settings. Is is possible to use an IoC this way?

dukesta3
  • 137
  • 7

1 Answers1

0

When using IOC you generally configure all of your dependencies in your application root and these will be unchanging for the life of the application.

For any configurable/changeable dependencies you should take a dependency on an abstract factory which will do the work of creating the inital dependency with the configurable behaviour.

See here for a pretty good overview of the pattern

Community
  • 1
  • 1
Daniel Powell
  • 8,143
  • 11
  • 61
  • 108