Hi, did something change recently regarding the Fetch Client ?
I am trying to get the IHttpClient setup in a service class, using the example in the documentation. Like this:
constructor(@newInstanceOf(IHttpClient) readonly http: IHttpClient) {
http.configure(config =>
config
.withBaseUrl('/api/')
.withDefaults({
credentials: 'same-origin',
headers: {
'Accept': 'application/json',
'X-Requested-With': 'Fetch'
}
})
.withInterceptor({
async response(response) {
if(response.ok && response.headers.get('Content-Type').startsWith('application/json')) {
const data = await response.json();
return data
}
return response;
}
}
));
}
The browser console is giving me the following error:
Error: AUR0017: Failed to instantiate ‘InterfaceSymbol’ via @newInstanceOf /@newInstanceForScope , there’s no registration and no default implementation.
These are my imports:
import {IHttpClient} from '@aurelia/fetch-client';
import { newInstanceOf } from '@aurelia/kernel';
1 Like
I don’t know the details, but there was a recent fix regarding IHttpClient injection:
opened 09:53AM - 15 Feb 24 UTC
closed 11:53AM - 23 Feb 24 UTC
<!---
Thanks for filing an issue 😄 ! Before you submit, please read the followi… ng:
Search open/closed issues before submitting since someone might have asked the same thing before!
-->
# 🐛 Bug Report
As per the discussion here: https://discourse.aurelia.io/t/typescript-to-vanilla-js-for-injecting-ihttpclient/5272/2
## 🤔 Expected Behavior
Should be able to inject a new instance of IHttpClient without getting an error.
## 😯 Current Behavior
```
export class ApiService {
http = resolve(newInstanceOf(IHttpClient))
}
```
```
export class ProductionApiService {
constructor() {
this.http = resolve(newInstanceOf(IHttpClient))
}
}
```
```
@inject(newInstanceOf(IHttpClient))
```
Results in this error:
```
AUR0017:InterfaceSymbol<IHttpClient>
at createMappedError (webpack-internal:///./node_modules/@aurelia/kernel/dist/esm/index.mjs:80:40)
at createNewInstance (webpack-internal:///./node_modules/@aurelia/kernel/dist/esm/index.mjs:1254:15)
at eval (webpack-internal:///./node_modules/@aurelia/kernel/dist/esm/index.mjs:1241:54)
at Resolver.resolve (webpack-internal:///./node_modules/@aurelia/kernel/dist/esm/index.mjs:1174:20)
at Container.get (webpack-internal:///./node_modules/@aurelia/kernel/dist/esm/index.mjs:629:22)
at Container.containerGetKey (webpack-internal:///./node_modules/@aurelia/kernel/dist/esm/index.mjs:871:17)
at Array.map (<anonymous>)
at Factory.construct (webpack-internal:///./node_modules/@aurelia/kernel/dist/esm/index.mjs:843:56)
at Resolver.resolve (webpack-internal:///./node_modules/@aurelia/kernel/dist/esm/index.mjs:1283:57)
at Container.get (webpack-internal:///./node_modules/@aurelia/kernel/dist/esm/index.mjs:642:34)
```
Ahh, looks like something happened.
I tried beta 10 and it works as documented. Maybe I’ll hang tight until beta 12.
Thanks!
beta 12 fixed this. Thanks!
1 Like