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

Is there any vscode extension to navigate to class Implementation indicated in container resolve ? #197

Open
MAMISHO opened this issue May 18, 2022 · 2 comments

Comments

@MAMISHO
Copy link

MAMISHO commented May 18, 2022

I have a some classes that implement an interface. Those have injection decorator to work as Services. The problem is when I debug and I want to navigate to some implementation. Always I go to container.resolve and then I found a specific class. Is there any shortcut or vscode extension to help navigate directly to implementation ?.

This is an example.

loader.ts file -> called from index.ts

container.register('IUserRepository', {
  useClass: UserRepositoryImpl,
});
container.register('IUserRepositoryService', {
  useClass: UserRepositoryServiceImpl,
});
const userRepository = container.resolve(UserRepositoryImpl);
const userRepositoryService = container.resolve(UserRepositoryServiceImpl);

export const UserRepository = userRepository;
export const UserRepositoryService = userRepositoryService;

user-repository.interface.ts

export interface IUserRepositoryService {
  findOne(userId: number): Promise<UserDTO>;
  findOneByUUID(uuid: string): Promise<UserDTO>;
  findOneComplete(userId: number): Promise<UserDTO>;
  findOneByUUIDComplete(userId: string): Promise<UserDTO>;
  findAll(filter: UserCriteriaDTO): Promise<UserDTO[]>;
  findAllComplete(filter: UserCriteriaDTO): Promise<UserDTO[]>;
  save(userDTO: UserDTO): Promise<UserDTO>;
}

user-repository.service.ts

... imports...
@injectable()
export class UserRepositoryServiceImpl implements IUserRepositoryService {
  constructor(@inject('IUserRepository') private userRepository: IUserRepository) {}

  public async findOne(userId: number): Promise<UserDTO> {
    let userDTO: UserDTO;
    const user: IUser = await this.userRepository.get(userId);
    if (user) {
      userDTO = user as UserDTO;
      return Promise.resolve(userDTO);
    }
    return Promise.reject(new Error('User not found'));
  }
...
....
others methods
...
...

user-controller.ts

getUsers: async (req: Request, res: Response) => {
    const sessionUser = req.session?.user;
    const request: UserRequestDTO = {};
    ....
    .....
    .....
    try {
      const users: UserDTO[] = await UserRepositoryService.findAll(request); // I want to navigate from here to UserRepositoryServiceImpl like netbeans or other IDEs
      return res.status(200).send(users);
    } catch (error) {
      return res.status(400).send(error);
    }
  },
@emilioastarita
Copy link
Contributor

Something like: Go to Implementation ?
https://code.visualstudio.com/docs/editor/editingevolved#:~:text=Go%20to%20Implementation%23,concrete%20implementations%20of%20that%20method.

@luisdemarchi
Copy link

The VScode on windows are able to navigate directly to the interface implementation, unfortunately I can't find a command for this on mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants