title: Cannot inject the dependency "modelRepository" at position #0 of "GetModelService" constructor. Reason: Cannot read property 'name' of undefined
body: <p>i've been using <strong><code>sequelize-typescript</code></strong>, <strong><code>tsyringe</code></strong> on a refactor work here and i got a pretty interesting bug here.
  Well normally all of my repository containers is being registered normally and instanced properly with the follow settings:</p>
  <ul>
  <li><p>i import the reflect metadata on the root of my application and the <code>tsyringe</code> container after it</p>
  <pre><code>import 'reflect-metadata';
  import 'dotenv/config';
  import express, { Request, Response, NextFunction } from 'express';
  ...
  import '@shared/infra/sequelize/index'; // default sequelize connection
  import '@shared/container/index';
  </code></pre>
  </li>
  <li><p>Inside of container/index is the following code, im using <code>sequelize-typescript</code> to craft the repositories.</p>
  <pre><code>
  import { container } from 'tsyringe';
  
  import IUsersRepository from '@modules/users/repositories/IUsersRepositories';
  import UsersRepository from '@modules/users/infra/sequelize/repositories/UserRepository';
  ...
  import IModelRepository from '@modules/model/repositories/IModelRepository';
  import ModelRepository from '@modules/model/infra/sequelize/repositories/ModelRepository';
  
  container.registerSingleton&lt;IUsersRepository&gt;(
    'UsersRepository',
    UsersRepository,
  );
  ...
  container.registerSingleton&lt;IModelRepository&gt;(
    'ModelRepository',
    ModelRepository,
  );
  </code></pre>
  </li>
  <li><p>then i do all of the routering with express:</p>
  <pre><code>import { Router } from 'express';
  import bdDecider from '@shared/infra/http/middlewares/bdDecider';
  import ensureAuthenticated from '@modules/users/infra/http/middlewares/EnsureAuthenticated';
  import UserRouter from '@modules/users/infra/http/routes/user.routes';
  ...
  import ModelRouter from '@modules/model/infra/http/routes/model.routes';
  
  const routes = Router();
  
  routes.use('/sessions', SessionRouter);
  routes.use(ensureAuthenticated);
  routes.use(bdDecider); //bdDecider as it says gets the logged on user bdConfig so i can connect to it
  routes.use('/model', ModelRouter);
  </code></pre>
  </li>
  <li><p>so we go to the route that calls <code>container.resolve()</code></p>
  <pre><code>import { container } from 'tsyringe';
  import { Response, Request } from 'express';
  import ShowModelsService from '@modules/invoices/services/ShowModelsService';
  
  export default class ShowModelsController {
    public async show(req: Request, res: Response): Promise&lt;Response&gt; {
      const { id } = req.params;
  
      const showModelsService = container.resolve( //it calls the model service
        ShowModelsService,
      );
  
      const models = await showModelsService.execute(
        id,
      );
  
      return res.json(models);
    }
  }
  </code></pre>
  </li>
  <li><p>here is the service that he calls</p>
  <pre><code>import IModelRepository from '@modules/model/repositories/IModelRepository';
  import AppError from '@shared/errors/AppError';
  import { inject, injectable } from 'tsyringe';
  import IModelDTO from '../dtos/IModelDTO';
  
  type IResponse = IModelDTO;
  
  @injectable()
  export default class ShowModelService {
    constructor(
      @inject('ModelRepository')
      private modelRepository: IModelRepository,
    ) {}
  
    public async execute(id: string): Promise&lt;IResponse&gt; {
      const model = await this.modelRepository.get_models(
        id,
      );
  
      if (!model) {
        throw new AppError('Model not found!', 404);
      }
  
      return model;
    }
  }
  </code></pre>
  </li>
  <li><p>Till there everything is fine and works properly, but when i try to associate that model with another one using <code>sequelize</code>. <code>Tsyringe</code> stops being able to properly inject the dependencies and gives the title error message. Here it is the models i'm trying to associate.</p>
  <pre><code>import Model from '@modules/model/infra/sequelize/entities/Model';
  import { DataTypes } from 'sequelize';
  import { Sequelize } from 'sequelize-typescript';
  import User from '../entities/User';
  export default (sequelize: Sequelize): void =&gt; {
  Model.init(
      {
        primary: {
          allowNull: false,
          autoIncrement: true,
          primaryKey: true,
          type: DataTypes.INTEGER,
        },
        camp1: DataTypes.DECIMAL(20, 2),
        camp2: DataTypes.DATE,
      },
      {
        tableName: 'tbl_model',
        sequelize,
      },
    );
    Model.hasMany(User);
  }
  </code></pre>
  </li>
  <li><p>if i remove that &quot;<code>Model.hasMany(User);</code>&quot; it goes back to normal and the injection happens, i'm very confused to know whats going on...</p>
  </li>
  <li><p>by the way here is my model repository</p>
  <pre><code>import IModelRepository from '@modules/model/repositories/IModelRepository';
  import AppError from '@shared/errors/AppError';
  import { connection } from '@shared/infra/http/middlewares/bdDecider';
  import { Repository } from 'sequelize-typescript';
  import IModelDTO from '@modules/model/dtos/IModelDTO';
  import initModel from '../utils/initInvoice';
  import initUser from '../utils/initItem';
  import Model from '../entities/Model';
  import User from '../entities/User';
  
  export default class ModelRepository implements IModelRepository {
    private ormRepository: Repository&lt;Model&gt;;
  
    constructor() {
      if (!connection) {
        throw new AppError(
          `You don't have a client settled on your user credentials or you don't have a client settled or both`,
        );
      }
      initModel(connection); // it Model.init() the model with the hasmany association
      initUser(connection); // it User.init()
      this.ormRepository = connection.getRepository(Model);
    }
    public async get_models(
      id: string,
    ): Promise&lt;IModelDTO | null&gt; {
      const models = await this.ormRepository.findOne({
        where: { id },
        include: [
          {
            model: User,
          },
        ],
      });
      return models;
    }
  }
  
  </code></pre>
  </li>
  <li><p>I'm sorry if this is too much information, but i tried to give as much as possible so someone could maybe help me.. But honestly i'm kinda skeptical about finding a solution, probably i'll have to detach this method from this model and try to do it separately. As you noticed i changed the names of the models so i might have misspelled something but don't worry with that there's not misspelling on the actual code because this bug only happens when i add &quot;<code>Model.hasMany(User);</code>&quot; to the <code>initModel()</code> function. Hopefully someone will be able to help me, any questions i'll be around don't be afraid to ask. :)</p>
  </li>
  </ul>