tsyringe
tsyringe copied to clipboard
Is there any vscode extension to navigate to class Implementation indicated in container resolve ?
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);
}
},
Something like: Go to Implementation ? https://code.visualstudio.com/docs/editor/editingevolved#:~:text=Go%20to%20Implementation%23,concrete%20implementations%20of%20that%20method.
The VScode on windows are able to navigate directly to the interface implementation, unfortunately I can't find a command for this on mac