An open-source entry in TopGit's GitHub warehouse: typestack/typeorm-typedi-extensions, 261 stars, TypeScript. Dependency injection and service container integration with TypeORM using TypeDI library.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Import the reflect-metadata package at the first line of your application:
import 'reflect-metadata';
// Your other imports and initialization code
// comes here after you imported the reflect-metadata package!
You need to enable emitting decorator metadata in your Typescript config. Add these two lines to your tsconfig.json file under the compilerOptions key:
Configure TypeORM in your app to use the TypeDI container before you create a connection:
import { createConnection, useContainer } from 'typeorm';
import { Container } from 'typeorm-typedi-extensions';
// ▲ Notice how we import container from this library, instead of TypeDI.
/** Tell TypeORM to use the container provided by this lib to resolve it's dependencies. */
useContainer(Container);
/** Create a connection and start using TypeORM. */
createConnection({
/* <connection options> */
}).catch(error => {
console.error(`Couldn't connect to the database!`);
console.error(error);
});
Usage
This package exposes three decorators all three decorators can be used on properties or on constructor parameters.
IMPORTANT:
To allow TypeDI to resolve the dependencies on your classes you must mark them with @Service decorator from the TypeDI package.
@InjectConnection decorator
Injects Connection from where you can access anything in your connection.
Optionally, you can specify a connection to inject by name in the decorator parameter.
import { Service } from 'typedi';
import { Connection } from 'typeorm';
import { InjectConnection } from 'typeorm-typedi-extensions';
@Service()
export class MyCustomClass {
@InjectConnection()
private propertyInjectedConnection: Connection;
constructor(@InjectConnection() private constructorInjectedConnection: Connection) {}
}
@InjectManager decorator
Injects EntityManager from where you can access any entity in your connection.
Optionally, you can specify a connection to inject by name in the decorator parameter.
import { Service } from 'typedi';
import { EntityManager } from 'typeorm';
import { InjectManager } from 'typeorm-typedi-extensions';
@Service()
export class MyCustomClass {
@InjectManager()
private propertyInjectedEntityManager: EntityManager;
constructor(@InjectManager() private constructorInjectedEntityManager: EntityManager) {}
}
@InjectRepository decorator
Injects Repository, MongoRepository, TreeRepository or custom repository of some Entity.
Optionally, you can specify a connection to inject by name in the decorator parameter.
import { Service } from 'typedi';
import { Repository } from 'typeorm';
import { InjectRepository } from 'typeorm-typedi-extensions';
// MyDatabaseModel is a TypeORM entity (class marked with `@Entity()` decorator)
import { MyDatabaseModel } from './entities/post.entity.ts';
@Service()
export class MyCustomClass {
@InjectRepository(MyDatabaseModel)
private propertyInjectedRepository: Repository<MyDatabaseModel>;
constructor(@InjectRepository(MyDatabaseModel) private constructorInjectedRepository: Repository<MyDatabaseModel>) {}
}
You can also inject custom Repository of some Entity. To make this work have to create the class which extends the
generic Repository<T> class and decorate it with EntityRepository<T> decorator.
import { Service } from 'typedi';
import { Repository, EntityRepository } from 'typeorm';
import { InjectRepository } from 'typeorm-typedi-extensions';
// UserModel is a TypeORM entity (class marked with `@Entity()` decorator)
import { UserModel } from './entities/user.entity.ts';
@Service()
@EntityRepository(UserModel)
export class UserRepository extends Repository<UserModel> {
public findByEmail(email: string) {
return this.findOne({ email });
}
}
@Service()
export class PostService {
constructor(
@InjectRepository()
private readonly userRepository: UserRepository
) {}
public async userExist(user: User): boolean {
return (await this.userRepository.findByEmail(user.email)) ? true : false;
}
}
Does typestack/typeorm-typedi-extensions have any tags?
TopGit's last sync did not record any GitHub topics for typestack/typeorm-typedi-extensions. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on typestack/typeorm-typedi-extensions?
The most recent commit recorded on typestack/typeorm-typedi-extensions was 3.0 years ago, based on the GitHub push timestamp. The repository has 33 forks — one of the better signals of community interest.
How many stars does typestack/typeorm-typedi-extensions have?
typestack/typeorm-typedi-extensions has 261 GitHub stars — refresh the page for the live number, or check github.com/typestack/typeorm-typedi-extensions. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What is typestack/typeorm-typedi-extensions?
typestack/typeorm-typedi-extensions (typestack/typeorm-typedi-extensions) is a TypeScript project on GitHub. From the project's own README: Dependency injection and service container integration with TypeORM using TypeDI library.
What language is typestack/typeorm-typedi-extensions written in?
typestack/typeorm-typedi-extensions is written primarily in TypeScript. GitHub's language field is based on the largest share of bytes in the default branch.
Read full README in the tab above.
Still deciding about typeorm-typedi-extensions?
One click hands the question to an AI along with this page — see what it says about typeorm-typedi-extensions.