AdonisJS API
    Preparing search index...

    Function inject

    • The "@inject" decorator uses Reflection to inspect the dependencies of a class or a method and defines them as metadata on the class for the container to discover them.

      Returns {
          <C extends Function>(target: C): void;
          (target: any, propertyKey: string | symbol): void;
      }

      @inject()
      class UsersController {
      constructor(private database: Database) {}
      }
      class UsersController {
      @inject()
      async index(request: Request, response: Response) {
      // Method with dependency injection
      }
      }