guaka
v0.0.7
Published
[![trunk](https://github.com/jasonkuhrt/template-typescript-lib/actions/workflows/trunk.yaml/badge.svg)](https://github.com/jasonkuhrt/template-typescript-lib/actions/workflows/trunk.yaml)
Downloads
2
Readme
GUAKA
Guaka is a dependency injection tool for TypeScript. With it you can build DDD aplication.
Main features includes:
- property based injection
- constructor based injection
- singleton and transient services
- support for multiple DI containers
Installation
Note: This installation guide is for usage with TypeScript
To start using Guaka install the required packages via NPM:
npm install guaka reflect-metadata
As a last step, you need to enable emitting decorator metadata in your Typescript config. Add these two lines to your tsconfig.json
file under the compilerOptions
key:
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
Now you are ready to use Guaka with Typescript!
Basic Usage
import { Repository, Domain } from 'guaka';
@Repository({key: 'exampleRepository'})
class ExampleRepository {
logMessage() {
console.log('Hello!!');
}
}
@Domain({key: 'exampleDomain'})
class ExampleDomain {
ExampleRepository:ExampleRepository;
constructor(
@inject({ key:"exampleRepository"}) ExampleRepository?: ExampleRepository,
) {
this.ProductRespository = ProductRespository;
}
}
const serviceInstance = Factory('DOMAIN', 'exampleDomain');
// we request an instance of ExampleService from Guaka
serviceInstance.ExampleRepository.logMessage()
// logs "Hello!" to the console