Skip to main content

Clawject

Full-stack, type-safe, declarative Dependency Injection framework for TypeScript

DeclarativeGet Started
Clawject

Built for developers convenience

Clawject designed to make dependency injection and inversion of control in TypeScript as effortless, clear and intuitive as possible.
It allows define class dependencies in a declarative way, without the need to use injection tokens or any other boilerplate, especially when it comes to interfaces and generics.

Develop with Clawject
interface IRepository<T> { /*...*/ }
class RepositoryImpl<T> implements IRepository<T> { /*...*/ }
class PrimitivesService {
constructor(
private stringRepository: IRepository<string>,
private numberRepository: IRepository<number>,
private booleanRepository: IRepository<boolean>,
) {}
}

@ClawjectApplication
class Application {
stringRepository = Bean(RepositoryImpl<string>);
numberRepository = Bean(RepositoryImpl<number>);
booleanRepository = Bean(RepositoryImpl<boolean>);
primitivesService = Bean(PrimitivesService);
}

It's not only about the amount of code you write, but also about the clarity and readability of your code. Imagine how much time Clawject can save you. All this time can be used for more important things, like playing with your cat 🐈

Develop with other popular framework
interface IRepository<T> { /*...*/ }
@Injectable()
class RepositoryImpl<T> implements IRepository<T> { /*...*/ }
const InjectionTokens = {
StringRepository: Symbol('StringRepository'),
NumberRepository: Symbol('NumberRepository'),
BooleanRepository: Symbol('BooleanRepository'),
}

@Injectable()
class PrimitivesService {
constructor(
@Inject(InjectionTokens.StringRepository)
private stringRepository: IRepository<string>,
@Inject(InjectionTokens.NumberRepository)
private numberRepository: IRepository<number>,
@Inject(InjectionTokens.BooleanRepository)
private booleanRepository: IRepository<boolean>,
) {}
}

@Module({
providers: [
PrimitivesService,
{
provide: InjectionTokens.StringRepository,
useClass: RepositoryImpl,
},
{
provide: InjectionTokens.NumberRepository,
useClass: RepositoryImpl,
},
{
provide: InjectionTokens.BooleanRepository,
useClass: RepositoryImpl,
},
],
})
class Application {}

In-editor diagnostics support

With Clawject's language service plugin, you can get instant feedback about missing beans, incorrect types, circular dependencies and more. It will help you to catch errors early without running your application and make your development process more productive.

Split your code by features

Using @Configuration classes you can split your code by features. Encapsulate beans and expose only needed to the container. It will help you to keep your codebase clean and maintainable.

Externalize inversion of control

Forgot about tons of decorators on your business logic classes, with Clawject you can externalize inversion of control and keep your classes clean, readable and focused on business logic.

First class type safety

With Clawject - you will never have to worry about the injection tokens mismatch, type - is a source of truth. Stop defining complex factory providers just because you want to use interfaces or generics – Clawject will take care of it for you.