Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

'No injectable members ...' is an error? #527

Open
rodlogic opened this issue Apr 12, 2016 · 1 comment
Open

'No injectable members ...' is an error? #527

rodlogic opened this issue Apr 12, 2016 · 1 comment

Comments

@rodlogic
Copy link

Consider that DeleteBastion class has no injectable members and I have a factory class as follows:

    @Singleton
    public static class Factory {
        @Inject
        MembersInjector<DeleteBastion> injector;

        public DeleteBastion create(Regions region, Environment env) {
            DeleteBastion cmd = new DeleteBastion(region, env);
            injector.injectMembers(cmd);
            return cmd;
        }
    }

Compiling gives me the following error:

Error:(43, 8) java: No injectable members on DeleteBastion. Do you want to add an injectable constructor? required by DeleteBastion.Factory for Main

Now, the error message is pretty obvious since I don't have an injectable member in the DeleteBastion, but that is quite inconvenient. Right now I don't have an injectable member, but it is quite possible that I may have one in the future. Does that mean I need to manage this by commenting out code and uncommenting it when I do have an injectable member? Shouldn't this be a warning at most or am I missing something?

@GaborPeto
Copy link

As the logs suggest:
Do you want to add an injectable constructor?

This is what I usually do if I inject the class that doesn't have an injectable member. you can just add
@Inject public void DeleteBastion() {}
and you will not get an error. In the future if you want to inject a member in that class, just do that and remove the default constructor with the @Inject annotation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants