Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Inject in customRepository seems no work #33

Closed
ruiming opened this issue Jul 28, 2017 · 3 comments
Closed

@Inject in customRepository seems no work #33

ruiming opened this issue Jul 28, 2017 · 3 comments

Comments

@ruiming
Copy link

ruiming commented Jul 28, 2017

I have a service

@Service()
export class Discuz {
  ...
}

While I want to inject it in customRepository, however it seems no work.

@Service()
@EntityRepository(User)
export class UserRepository extends Repository<User> {
  @Inject() 
  discuz: Discuz
  
  async loginDiscuz (cookies: {}, body: {}) {
    console.log(this.discuz, Container.get(Discuz)) // This output undefined Discuz {}
  }
}

But this work:

@Service()
export class UserService {
  @OrmCustomRepository(UserRepository)
  userRepository: UserRepository

  @Inject() 
  discuz: Discuz

  async loginDiscuz (cookies: {}, body: {}): Promise<{ accessToken: string }> {
    console.log(this.discuz) // output Discuz {}
    return this.userRepository.loginDiscuz(cookies, body)
  }
}

Maybe @EntityRepository breaks the typedi?

@pleerock
Copy link
Contributor

@OrmCustomRepository is deprecated and must be removed. Because conception of custom repositories in typeorm has changed. Now custom repositories cannot be global services, instead they are specific to connection manager.

@ruiming
Copy link
Author

ruiming commented Jul 31, 2017

Thanks. I just removed @Service and use Container.get instead of @Inject.

@ruiming ruiming closed this as completed Jul 31, 2017
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants