You’ve not abstracted this correctly.
Inject a dependency (
IDependency) which has a method which returns a boolean. Your service does not need to know how the dependency works, it just knows that it will receive a boolean.
Based on your configuration, inject a different concrete class as the dependency.
- If you need to call a http client, inject
HttpClientDependency : IDependencywhich actually calls an external service and returns a meaningful boolean value.
- If you don’t need to call a http client, inject a
ReturnsTrueDependency : IDependencywhich does nothing more than
Regardless of which dependency is injected, your service class works the same way, which simplifies its logic and keeps it readable.
Note also that how you choose the right concrete class to inject is up to you. You could use a factory. Or you could wire your DI container differently at startup. This depends on what makes the most sense for your particular scenario.
These names are used as oversimplified examples. Better names should be used in your code.