declex icon indicating copy to clipboard operation
declex copied to clipboard

Inject bean with annotation

Open smaugho opened this issue 6 years ago • 0 comments

With the new @Export mechanism implemented with DecleX 2.0, several beans can be created which autocontain whole the behavior for a feature. Many times these beans create events which are enough to interact with them, without the need of referencing them directly, but they should be attached to a specific application component (ex, to the application activity)

Let's say we have a Bean which implement all the Facebook SDK login and other related features, in the MainActivity of a project, typically you need to declare:

@Bean
FacebookSDKManager manager;

some times it is not even necessary to use this object, since it is automatically coupled to the activity, but some times you need to use some features from it, or "configure it", like for instance:

@AfterInject
void configureFacebookSDKManager() {
   manager.setApiKey(...);
}

It would be good to have a mechanism which integrates all this into an annotation, which could automatically be handle by DecleX, and this will simulate the above mechanism to inject the object and initialize it.

for instance, this would permit to reduce everything above to a simple

@UseFacebook(apiKey = "...")
public class MainActivity extends Activity {

}

This could be done declaring the annotation in a library, with the fields, and when the bean is declared a special annotation is used to indicate declex should handle that annotation, for instance

@EBean @UseAnnotation(UseFacebook.class) ....

So, DecleX processes the @UseAnnotation, and it will start processing as well the UseFacebook automatically.

smaugho avatar Oct 07 '17 18:10 smaugho