How to import singletons #4442
Unanswered
ashokkumar88
asked this question in
Help
Replies: 1 comment
-
Hi @ashokkumar88, Here is a example with a provider: import type { ApplicationService } from '@adonisjs/core/types'
import Stripe from 'stripe'
import StripeConfig from '#config/stripe'
export default class StripeProvider {
constructor(protected app: ApplicationService) {}
register() {
this.app.container.singleton('max/stripe', async () => {
return new Stripe(StripeConfig.secretKey)
})
}
}
declare module '@adonisjs/core/types' {
interface ContainerBindings {
'max/stripe': Stripe
}
} And inside your controller you can do that: const stripe = await app.container.make('max/stripe') |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using Adonis 6. In app_provider.ts I have created a singleton like below. I want to import it in a controller.
this.app.container.singleton('App/GraphQL', () => graphql_middlewire);
I want to import the 'App/GraphQL' singleton in a controller.
Beta Was this translation helpful? Give feedback.
All reactions