Skip to content

5.0.0

Compare
Choose a tag to compare
@remojansen remojansen released this 26 Nov 10:42
· 349 commits to master since this release
b2fb762

New features

  • Reduced amount of required boilerplate code:

    • The @injectable annotation is no longer required in classes annotated with @controller.
    • Declaring bindings is no longer required in classes annotated with @controller.
  • Support for HttpContext:

    • The current HttpContext can be accessed from a controller that extends the BaseHttpController class or that gets it injected using the @injectHttpContext decorator.
    • The current HttpContext can be accessed from middleware that extends the BaseMiddleware class.
  • Support for BaseMiddleware. Extending BaseMiddleware allow us to inject dependencies into a middleware function. Extending BaseMiddleware also allows us to access the current HttpContext from a middleware function.

  • Support for AuthProvider. If you provide an implementation of AuthProvider, you will be able to access the current user via the current HttpContext.

Breaking changes

  • The @injectable annotation is no longer required in classes annotated with @controller.
  • Declaring bindings is no longer required in classes annotated with @controller.

⚠️ Declaring a binding is not required for Controllers but it is required to import the controller one unique time. When the controller file is imported (e.g. import "./controllers/some_controller") the class is declared and the metadata is generated. If you don't import it the metadata is never generated and therefore the controller is not found. An example of this can be found here.

If you run the application multiple times within a shared runtime process (e.g. unit testing) you might need to clean up the existing metadata before each test.

import { cleanUpMetadata } from "inversify-express-utils";

describe("Some Component", () => {

    beforeEach(() => {
        cleanUpMetadata();
    });

    it("Some test case", () => {
        // ...
    });

});

You can find an example of this in our unit tests.