Skip to content

Add support for defining @Components in @Configuration classes #20

Open

Description

@saskodh

Background

The @configuration classes should provide way for manually creating the components in the DI container. This is really important especally for instances of classes which cannot be decorated with @component and picked-up by the @componentscan.

Goal

Add support for creating components from the methods in @configuration classes decorated with @component similar like Spring. For more info check the Spring documentation on configuration classes (Link).

Task

Extend @component decorator so it can be used also on methods in @configuration classes

Implementation detail: TypeScript has few types of decorators depending on the place where they are used. They can be differentiated by the arguments that are passed to the decorator function. That means that we can create a universal decorator that can be used on all places. In this patch I wrote a small util that can infer the decorator type from it's arguments.

Note:

  • @Inject and @value should also work in @configuration classes -> in that way we can get the dependencies from imported configuration classes
  • @configuration class needs to be proxied in order to respect the component scope -> local dependencies will be fetched by calling the component definition method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions