@goodie-ts/decorators
v0.5.3
Published
Stage 3 decorators for goodie-ts compile-time dependency injection
Readme
@goodie-ts/decorators
Stage 3 decorators for goodie-ts compile-time dependency injection.
Install
pnpm add @goodie-ts/decoratorsOverview
Provides the decorators you use to annotate your classes. These attach metadata via Symbol.metadata which the transformer reads at build time — they do not wire anything at runtime. No reflect-metadata required.
Decorators
| Decorator | Target | Description |
|-----------|--------|-------------|
| @Singleton() | class | Singleton-scoped bean |
| @Injectable() | class | Prototype-scoped bean (new instance per lookup) |
| @Named(name) | class | Qualifier for disambiguation |
| @Eager() | class | Instantiate at startup instead of on first access |
| @Module({ imports? }) | class | Groups @Provides factory methods |
| @Provides() | method | Marks a method in a @Module as a bean factory |
| @Inject(qualifier?) | accessor field | Field injection |
| @Optional() | accessor field | Marks a field as optional (resolves to undefined if missing) |
| @Value(key, { default? }) | accessor field | Injects a config value by key |
| @PostConstruct() | method | Called after bean construction and field injection |
| @PreDestroy() | method | Called during ApplicationContext.close() |
| @PostProcessor() | class | Marks bean as a BeanPostProcessor |
Usage
import { Singleton, Inject, Optional } from '@goodie-ts/decorators';
@Singleton()
class UserService {
@Inject() accessor userRepo!: UserRepository;
@Optional() accessor logger?: Logger;
getUsers() { return this.userRepo.findAll(); }
}Note:
@Injectand@Optionalrequire theaccessorkeyword — Stage 3 decorators do not support parameter decorators.
