If I understood correctly, in order to create your CommunicationClient class, you need to pass the information received by the method call in the instance of your ISettingsManager , but you do not want to pass the ISettingsManager as a dependency on your CommunicationClient ?
One solution to this would be to create and register a factory, which will be dependent on ISettingsManager , and it will have a CreateClient method that will return the configured client.
public class CommunicationClientFactory : ICommunicationClientFactory { public CommunicationClientFactory(ISettingsManager settingsManager) {...} public CreateClient() {...} }
Thus, your CommunicationClient is independent of ISettingsManager , and you only have this factory that does the work of creating your instance.
Edit: An alternative, if you do not want to create a factory for this, would be to create your CommunicationClient object in an "invalid" state and have a method that sets the settings and makes its state valid.
Sort of:
public class CommunicationClient : IClient { public CommunicationClient() { ... }
Of course, then you will need to make sure that the user is not using it when the settings have not yet been passed, perhaps throwing an exception if that is the case. I like this solution less because it is less explicit that you need these settings to display your object in the correct state.
source share