createInjector(Stagestage, Module...modules)
Stage.DEVELOPMENT和Stage.PRODUCTION' 注入提供者
后者将会在初始化的时期就早期进行注入
前者在用到时方会进行注入
- publicclassMyModuleimplementsModule{
- publicvoidconfigure(Binderbinder){
- //BindFootoFooImpl.Guicewillcreateanew
- //instanceofFooImplforeveryinjection.
- binder.bind(Foo.class).to(FooImpl.class);
- //绑定实例
- //BindBartoaninstanceofBar.
- Barbar=newBar();
- binder.bind(Bar.class).toInstance(bar);
- }
- }
type
)将会返回一个泛型的实例
getProvider(type).get()