The APIURLProviding protocol allows injecting a base URL for contacting the backend, however the absence of a trailing slash is an implicit contract all clients of the dependency need to be aware of. This causes breakages when concatenating a path without the slash.
Instead of injecting a value, passing in a factory to give us back a prepared URL for a path moves this knowledge into the dependency and allows clients to not care about the structure of the URL being passed in.
The
APIURLProviding
protocol allows injecting a base URL for contacting the backend, however the absence of a trailing slash is an implicit contract all clients of the dependency need to be aware of. This causes breakages when concatenating a path without the slash.Instead of injecting a value, passing in a factory to give us back a prepared URL for a path moves this knowledge into the dependency and allows clients to not care about the structure of the URL being passed in.