Code Monkey home page Code Monkey logo

Comments (2)

PodaruDragos avatar PodaruDragos commented on June 1, 2024

hey @b1ff .

I saw that you've made a PR for this. but it's already possible to do this in inversify-express-utils. Let me give you an example.

@injectable()
export class AuthorizationMiddleware extends BaseMiddleware {
  @inject(TYPES.USER_REPOSITORY)
  private readonly userRepository!: EntityRepository<User>;

  constructor(
    @inject(TYPES.USER_REPOSITORY)
    private readonly userRepositoryFromConstructor: EntityRepository<User>
  ) {
    super();
  }

  public handler(_req: Request, _res: Response, next: NextFunction): void {
    console.log(this.userRepository);
    console.log(this.userRepositoryFromConstructor);
    next();
  }
}

And then for the container binding

container.bind(AuthorizationMiddleware).toSelf();

Is this what you were looking for ?

from inversify-express-utils.

b1ff avatar b1ff commented on June 1, 2024

@PodaruDragos hey there, not really. The issue is when I do

this.bind(..).to...();

in middleware, I cannot inject it using constructor to middleware. I have to use httpContext.containter.get(). While it works as workaround, it is better from testability and cleanness to inject it via middleware constructor, even if it was bound to container on httpContext.
You might see that behavior in test that I have added.

from inversify-express-utils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.