Real quick, using nswag to generate a client service, trying to configure the api base url by using injection token.
The generated code by nswag:
All of these ideally should NOT be touched, otherwise you will lose the changes on every regeneration. Ideally the baseURL should come from Dependency Injection.
export const API_BASE_UR = new InjectionToken<string>('API_BASE_URL');
constructor(@Inject(HttpClient) http: HttpClient, @Optional() @Inject(API_BASE_URL) baseUrl?: string) {
this.http = http;
this.baseUrl = baseUrl !== undefined && baseUrl !== null ? baseUrl : "";
}
So, let's configure the dependency injection
//Import the service to get the API_BASE_URL
import {API_BASE_URL} from 'blablablá....';
// Configure provider section
providers: [
{
provide: API_BASE_URL,
useValue: 'http://testUrl'
}
Expected: baseUrl to have "http://testUrl"
Actual: baseUrl is null
What is missing here in order to configure this properly?