Service provider does not call the method from service #4064
-
I am trying to create a new service provider for an external service I want to use, but when I call a method of the service I am getting the following error TypeError: Oblio_1.default.generateInvoice is not a function I've done this before and everything worked just fine, but now, it just won't work. so, I've created a // file: services/oblio/OblioService.ts
export class OblioService {
public async generateInvoice() {}
} I've created the service provider // file: providers/OblioProvider.ts
export default class OblioProvider {
constructor(protected app: ApplicationContract) {}
public register() {
// Register your own bindings
}
public async boot() {
this.app.container.singleton('App/Invoicing/Oblio', async () => {
const { OblioService } = require('./../services/oblio/OblioService')
const client = axios.create({
baseURL: 'https://test.test',
})
return new OblioService(client)
})
}
public async ready() {
// App is ready
}
public async shutdown() {
// Cleanup, since app is going down
}
} in // file: contracts/oblio.ts
declare module '@ioc:App/Invoicing/Oblio' {
import { OblioService } from 'Services/oblio/OblioService'
const OblioInvoice: OblioService
export default OblioInvoice
} in my controller I'm calling the service like this: import OblioInvoice from '@ioc:App/Invoicing/Oblio'
await OblioInvoice.generateInvoice(invoice) and here I am getting the error
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hmm, shouldn't you move |
Beta Was this translation helpful? Give feedback.
-
Please explain why you are registering a service provider for an app-level service? class OblioService {
public async generateInvoice(invoice) {}
}
const client = axios.create({
baseURL: 'https://test.test',
})
const oblioService = new OblioService(client)
export default oblioService import OblioInvoice from 'App/Invoicing/Oblio'
await OblioInvoice.generateInvoice(invoice) |
Beta Was this translation helpful? Give feedback.
Please explain why you are registering a service provider for an app-level service?
Why not directly import it inside your code?