sting-ioc / sting

Home Page:https://sting-ioc.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a gathering annotation to simplify constructing injectors

realityforge opened this issue · comments

Currently adding all injectables/fragments to an injector means adding them to a global list which often results in conflicts during git merges. Instead we could add a "gathering" annotation processor that collected all the bindings and added them to a single fragment that could be added to the injector.

Each @Injectable and @Fragment annotated type could have an annotation like @ContributeTo('SomeKey') and we would have another type annotated with @CollectContributors('SomeKey') annotation that generates a @Fragment type that is included in the injector. Emitting the generated @Fragment type before processing completes may be difficult in normal adhoc builds but in more controlled build environments (i.e. Bazel), this strategy would work well.

Considering naming the annotations @ContributeToAutoFragment("SomeKey") and @AutoFragment("SomeKey") with a @StringProvider on @AutoFragment so can just add the @AutoFragment annotated type to includes parameter

After experimentation it seems @ContributeTo("SomeKey") is more palatable.

The auto-fragment key defaults to the simple name to the class to which is attached.