We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created a provider called "EventManager" and tried inject it on Application class to be invoked on postServerInitialization()
postServerInitialization()
But received this error on start the server:
npm ci
npm run dev
1.5.1
18.14.0
di-issue.zip
The text was updated successfully, but these errors were encountered:
After read the doc of Inversify I solved this problem doing the following changes:
application.provider.ts
const appInstance = new App(); export { appInstance as App };
to
export { App };
--
src/main.ts
const app = App.create(container);
const app = container.get(App); app.create(container);
And it's works as expected:
Opened this issue because I believe it is a problem in the template as it does not accept injecting dependency into the Application class.
Sorry, something went wrong.
Hi @AntonyZ89 to resolve this issue in the proper manner I would recommend you to do this instead:
@provide(TwitchProvider) class TwitchProvider { async getAuthProvider(): Promise<string> { return randomUUID(); } } export { TwitchProvider };
Use the container to request services, instances like the code below:
@provide(App) class App extends Application { private twitchProvider: TwitchProvider; constructor() { super(); this.twitchProvider = container.get<TwitchProvider>(TwitchProvider); } protected configureServices(): void { Environments.checkAll(); } // eslint-disable-next-line @typescript-eslint/no-empty-function protected postServerInitialization(): void { console.log(this.twitchProvider.getAuthProvider()); } protected serverShutdown(): void { log(LogLevel.Info, "Server is shutting down", "logger-provider"); super.serverShutdown(); } } const appInstance = new App(); export { appInstance as App };
This is a very similar approach to .NET core on requesting services from the DI system, and how we are using at the moment on ExpressoTS
serviceProvider.GetRequiredService<SERVICES.Core.IAuthService>();
Let me know if it is working fine for you, so that I can close this ticket.
@rsaz Thanks, it works!
rsaz
No branches or pull requests
Is there an existing issue for this?
Current behavior
Created a provider called "EventManager" and tried inject it on Application class to be invoked on
postServerInitialization()
But received this error on start the server:
Steps to reproduce
npm ci
npm run dev
Expected behavior
Package version
1.5.1
Node.js version
18.14.0
In which operating systems have you tested?
Other
di-issue.zip
The text was updated successfully, but these errors were encountered: