saskodh / framework

Lightweight web framework for NodeJS inspired by Spring framework
26 stars 5 forks source link

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

Open saskodh opened 8 years ago

saskodh commented 8 years ago

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: