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
Implement dependency injection decorator
import { BaseInject, createInjector } from 'prismy-di' const PRODUCTION = process.env.NODE_ENV === 'production' const ServiceTypes = { MailService: 'MailService', NotificationService: 'NotificationService' } abstract class MailService { } class LiveMailService implements MailService { } class MockMailService implements MailService { } class NotificationService { constructor(@BaseInject(ServiceTypes.MailService) mailer: MailService) { ... } } const container = { [ServiceTypes.MailService]: PRODUCTION ? LiveMailService : MockMailService, [ServiceTypes.NotificationService]: NotificationService } const { Inject, injector } = createInjector(container) class MyHandler { handle(@Inject(ServiceTypes.NotificationService) notifier: NotificationService) { ... // Or const notifier = injector.inject(ServiceTypes.NotificationService) // Or const notifier = injector.instantiate(NotificationService) } }
The text was updated successfully, but these errors were encountered:
Maybe we don't need decorators.
See https://github.com/jeffijoe/awilix
Sorry, something went wrong.
No branches or pull requests
Implement dependency injection decorator
The text was updated successfully, but these errors were encountered: