protected final void init(ReadFileSystem<?> fs, ClassLoader classLoader) throws Exception { Injector bootstrap = getManager(); bootstrap.addFileSystem(fs); bootstrap.setClassLoader(classLoader); // this.bootstrap = bootstrap; this.fs = fs; }
@Override public void bind(Injector builder) { // Bind provider builder.bindProvider( declaredType, getScope(), getQualifiers(), implementationType); } };
protected static <B, I> InjectionContext<B, I> boot(Injector injector, Handler<Class<?>, Boolean> filter, Scope... scopes) throws Exception { for (Scope scope : scopes) { injector.addScope(scope); } if (filter == null) { return (InjectionContext<B, I>)injector.create(); } else { return (InjectionContext<B, I>)injector.create(filter); } }
@Test public void test() throws Exception { init(); bootstrap.declareProvider(Bean.class, null, null, BeanProvider.class); bootstrap.declareBean(Injected.class, null, null, null); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.dependency); }
@Test public void test() throws Exception { init(); bootstrap.bindBean(Injected.class, null, new Injected()); bootstrap.declareBean(Bean.class, Scope.SINGLETON, null, null); boot(); // Injected injected = getBean(Injected.class); Bean bean = getBean(Bean.class); assertNotNull(injected.bean); assertSame(bean, injected.bean); } }
@Override public void bind(Injector builder) { builder.declareBean(declaredType, getScope(), getQualifiers(), null); } };
@Test public void test() throws Exception { init(); Dependency dependency = new Dependency(); bootstrap.bindBean(Dependency.class, null, dependency); bootstrap.declareProvider(Bean.class, null, null, DependencyProvider.class); bootstrap.declareBean(Injected.class, null, null, null); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.product); assertSame(dependency, injected.product.dependency); } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, null); bootstrap.declareProvider(Bean1.class, null, null, Bean1Provider.class); bootstrap.declareProvider(Bean2.class, null, null, Bean2Provider.class); bootstrap.addFileSystem(fs); boot(); // Bean1 productExt1 = getBean(Bean1.class); assertNotNull(productExt1); // Bean2 productExt2 = getBean(Bean2.class); assertNotNull(productExt2); // Injected productInjected = getBean(Injected.class); assertNotNull(productInjected); assertNotNull(productInjected.productExt1); assertNotNull(productInjected.productExt2); } }
init(); HashSet singleton = new HashSet(); bootstrap.declareBean(Properties.class, Scope.SINGLETON, null, null); bootstrap.bindBean(HashSet.class, null, singleton); Injector injector = bootstrap.get(); bootstrap.declareBean(Date.class, Scope.SINGLETON, null, null); boot(); InjectionContext context = boot(injector);
Injector injector = injectorProvider.get(); injector.addFileSystem(classes); injector.setClassLoader(moduleLifeCycle.getClassLoader());
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, null); Bean blue = new Bean(); Bean red = new Bean(); Bean green = new Bean.Green(); bootstrap.bindProvider(Bean.class, null, Collections.<Annotation>singleton(new ColorizedLiteral(Color.BLUE)), new BeanProvider(blue)); bootstrap.bindProvider(Bean.class, null, Collections.<Annotation>singleton(new ColorizedLiteral(Color.RED)), new BeanProvider(red)); bootstrap.bindProvider(Bean.class, null, Collections.<Annotation>singleton(new ColorizedLiteral(Color.GREEN)), new BeanProvider(green)); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertSame(blue, injected.blue); assertSame(red, injected.red); assertSame(green, injected.green); } }
@Override public void bind(Injector builder) { // Bind provider builder.declareProvider( declaredType, getScope(), getQualifiers(), implementationType); } };
public abstract InjectionContext<?, ?> create(Handler<Class<?>, Boolean> filter) throws Exception;
if (injector.isProvided()) { bridge = new ProvidedBridge(bridgeContext, this.bridgeConfig, server, resolver, injector); } else {
@Test public void test() throws Exception { init(); bootstrap.declareProvider(Bean.class, null, null, BeanProducer.class); bootstrap.declareBean(Injected.class, null, null, null); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.dependency); } }
@Test public void test() throws Exception { Bean singleton = new Bean(); init(); bootstrap.declareBean(Injected.class, null, null, null); bootstrap.bindBean(Bean.class, null, singleton); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.dependency); assertSame(singleton, injected.dependency); } }
@Override public void bind(Injector builder) { builder.declareBean(declaredType, getScope(), getQualifiers(), null); } };
@Test public void test() throws Exception { init(); Dependency dependency = new Dependency(); bootstrap.bindBean(Dependency.class, null, dependency); bootstrap.declareProvider(Bean.class, null, null, DependencyProvider.class); bootstrap.declareBean(Injected.class, null, null, null); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.product); assertSame(dependency, injected.product.dependency); } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, null); bootstrap.declareProvider(Bean1.class, null, null, Bean1Provider.class); bootstrap.declareProvider(Bean2.class, null, null, Bean2Provider.class); bootstrap.addFileSystem(fs); boot(); // Bean1 productExt1 = getBean(Bean1.class); assertNotNull(productExt1); // Bean2 productExt2 = getBean(Bean2.class); assertNotNull(productExt2); // Injected productInjected = getBean(Injected.class); assertNotNull(productInjected); assertNotNull(productInjected.productExt1); assertNotNull(productInjected.productExt2); } }