sahan / IckleBot

A boilerplate code generator for Android providing runtime dependency injection and model-view binding along with simplified threading and event models.
http://sahan.me/IckleBot
Apache License 2.0
15 stars 3 forks source link

Injected properties null when used from subclasses of where they were originally injected. #4

Open jondwillis opened 11 years ago

jondwillis commented 11 years ago

Injection seems to fail, resulting in a thrown NullPointerException in the following case:

public abstract class BootstrapActivity extends IckleFragmentActivity {

    @InjectPojo(LogoutService.class)
    protected LogoutService logoutService;

}

...

public class DashboardActivity extends BootstrapActivity {
...
    private void logout() {
        // crash here, when logout() is called by user interaction or any other time.
        logoutService.logout(new Runnable() {
    }
}

Is this by design or is it intentional? Either way, it was unexpected behavior and is limiting my design.

jondwillis commented 11 years ago

Okay, this is because annotations cannot be inherited. I tried forking and adding @Inherited annotation to InjectPojo, but that did not work. I have limited knowledge of annotations, but I'll keep prying around a little bit.

sahan commented 11 years ago

@jondwillis, I remember putting this off and eluding to it in the documentation till the API became stable and all the implications of supporting features along an inheritance hierarchy were considered... and then I guess I forgot about it. Should have used gh-issues from the beginning.

In my opinion, if we allow a single feature to span the inheritance hierarchy it will make the whole API be perceived as such. So you'd expect other features like state management with @Stateful to be available as well. Supporting inheritance hierarchies should be an API-wide concern and I agree that it must be addressed. Let's start with dependency injection.

jondwillis commented 11 years ago

@sahan I agree, check out my pull request. I haven't thoroughly tested everything, but it is working right now for @InjectPojo in a very simple use-case.

jondwillis commented 11 years ago

@sahan PS, I am really enjoying this library in my most recent project. I'll try sharing it and endorsing it on various sites so it can get more love from the community.

sahan commented 11 years ago

A few things to consider,

...and possibly more.

@jondwillis, I'll review the pull request.

jondwillis commented 11 years ago

@sahan It was really more of a conversation starter than anything, but I appreciate it.

sahan commented 11 years ago

@jondwillis I went through the code and it looks good. I've added some line notes on jondwillis/IckleBot@a455c6f68617e532b9af0af5b1dc4a46cb90f45f based on my view. Mention me in a comment when you've reviewed them and I can merge the code.

sahan commented 11 years ago

@jondwillis And by the way, thank you for your personal endorsement. It's great to hear that someone's making use of it in a project.