Getting error in Singleton import #4444
Replies: 4 comments
-
You can find a complete example here: https://docs.adonisjs.com/guides/ioc-container#basic-example |
Beta Was this translation helpful? Give feedback.
-
Actually I am still not getting how to create the singleton and import it. Should i create in the |
Beta Was this translation helpful? Give feedback.
-
@ashokkumar88 does something like this work? // providers/app_provider.ts
import { ApplicationService } from "@adonisjs/core/types";
import graphql_middlewire from "#services/graphql_middlewire"; // adjust to your actual import
export default class AppProvider {
public static needsApplication = true;
constructor(protected app: ApplicationService) {}
public register() {
// Register your own bindings
this.app.container.singleton('App/GraphQL', () => new graphql_middlewire());
}
public async boot() {}
public async ready() {
// App is ready
}
public async shutdown() {
// Cleanup, since app is going down
}
}
// types/container.ts
declare module "@adonisjs/core/types" {
import graphql_middlewire from "#services/graphql_middlewire"; // use the proper import here
interface ContainerBindings {
"App/GraphQL": GraphQL;
}
} // some/other/file.ts
import app from "@adonisjs/core/services/app";
// ...
const graphql = await app.container.make("App/GraphQL"); |
Beta Was this translation helpful? Give feedback.
-
@e-e Thanks for your response. Actually i created a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Package version
6.2.2
Describe the bug
I have created a singleton in the app_provider.ts in the
boot() {}
method like below.Then in a helper file i imported it
import graphql_middlewire from "App/GraphQL"
. But it is giving errorCannot find package 'App'
Reproduction repo
No response
Beta Was this translation helpful? Give feedback.
All reactions