I have three projects, let's call them Project A, Project B, and Common.
Common, as you might've guessed, is a project containing files used in both projects.
There is a component, previously in Project A, that will now also be used in Project B, so I've moved it to Common. This component relies on a service, so it makes sense to me to also move the service to Common (service is a singleton). However, the service makes HTTP calls and there is a specific ID that is needed for the HTTP calls (it's part of the URLs).
The specific ID that is needed for the service's HTTP call is available in both Project A and in Project B, but they come from different sources, and it wouldn't be appropriate to move these sources to Common. So, I'm trying to figure out a way to perhaps conditionally pull the ID from either source, within the service, depending on which project is using the component, but I'm not sure what would be the best way to do this.
Something I considered was using a method to set the URL in the service, passing in what project is using the service, and then having it pull in the proper service from either Project A or Project B. But I'm not sure this is a great solution. Here's the pseudocode:
setBaseUrl(project) {
if (!this.baseURL) {
if (project === 'ProjectA') {
this.baseUrl += injector.get(projectAService).id;
} else {
this.baseUrl += injector.get(projectBService).id;
}
}
}
Any help would be much appreciated. Perhaps this is something that a wrapper class/inheritance could effectively solve, but right now I'm stumped.