onion-transformer
is a TypeScript transformer designed to simplify Dependency Injection (DI) in the Onion architecture. It automatically transforms TypeScript code to make dependency injections simpler and less error-prone.
- Automatic DI Metadata Addition: Simplifies dependency injection by automatically adding necessary metadata.
- Type safe DI: Types check on compile type
- Decorator Support: Recognizes and processes decorators used for dependency injections.
- Compatibility: Designed to work seamlessly with the Onion DI package, ensuring smooth integration.
Install onion-transformer
using npm or yarn:
npm install onion-transformer --save-dev
# or
yarn add onion-transformer --dev
npx ts-patch install
This step modifies the TypeScript compiler to support custom transformers.
To use onion-transformer in your project, add it to your TypeScript configuration (usually tsconfig.json) under compilerOptions.plugins:
{
"compilerOptions": {
"plugins": [
{
"transform": "onion-transformer"
}
]
}
}
@Service()
class MyService {
constructor(@Inject() private myOtherService: MyOtherService) {}
}
@Service({ name: "MyService" })
class MyService {
constructor(@Inject({ name: "MyOtherService" }) private myOtherService: MyOtherService) {}
}
- git clone https://github.com/Isqanderm/onion-transformer.git
- cd transformer
- npm install
- cd examples