Skip to content

TangTangG/AutoInject

Repository files navigation

AutoInject

This a project that can help you build your manager.
Especially for class that need to be controlled under different packages.
Like the Test(module).

package-a
    CollectionA.java
package-b
    CollectionB.java
CollectionC.java
CollectionIface.java
CollectionManager.java

Sometimes we want to holder all collection in CollectionManager.class, but Collection in different package.
If in same package,we can use java reflect to load them.
In different package,now you can do like this.

First Step

Add CollectionRegister annotation to the class.

@CollectionRegister(type = "c",target = CollectionIface.class)
public class CollectionC implements CollectionIface {
    @Override
    public void inject(Object[] args) {

    }
}

Second Step

Add Collector annotation to the manager field.

@Collector(CollectionIface.class)
Map<String,CollectionIface> collections = new HashMap<>(16);

Final Step

When the (Manager)Class be initialed,do like this:

AutoCollect.begin(new CollectionManager());

And then, you can use you Manager like used to.

How to initial Object with prams?

public interface CollectionIface extends InjectIface {
}

The super class extend/implements InjectIface,witch provider an common method

public void inject(Object[] args) {

}

but now this method has to call by yourself. In the next version we may call inject when it has been processored.

About

Auto inject mange container filed.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages