/** * Starts with fluent registration. */ public static PetiteRegistry of(final PetiteContainer petiteContainer) { return new PetiteRegistry(petiteContainer); }
/** * Creates {@link PetiteRegistry} helper tool for this container. */ public PetiteRegistry createContainerRegistry() { return PetiteRegistry.of(this); }
@Test void testManualRegistration2() { PetiteContainer pc = new PetiteContainer(); PetiteRegistry.of(pc).bean(SomeService.class).register(); PetiteRegistry.of(pc).bean(PojoBean.class).name("pojo").register(); assertEquals(2, pc.beansCount()); PetiteRegistry.of(pc).wire("pojo").ctor().bind(); PetiteRegistry.of(pc).wire("pojo").property("service").ref("someService").bind(); PetiteRegistry.of(pc).wire("pojo").method("injectService").ref("someService").bind(); PetiteRegistry.of(pc).init("pojo").invoke(POST_INITIALIZE).methods("init").register(); PojoBean pojoBean = pc.getBean("pojo"); SomeService ss = pc.getBean("someService"); assertNotNull(pojoBean); assertNotNull(ss); assertSame(ss, pojoBean.fservice); assertSame(ss, pojoBean.service); assertSame(ss, pojoBean.service2); assertEquals(1, pojoBean.count); }
@Test void testManualRegistrationUsingAnnotations2() { PetiteContainer pc = new PetiteContainer(); PetiteRegistry.of(pc).bean(SomeService.class).register(); PetiteRegistry.of(pc).bean(PojoAnnBean.class).name("pojo").register(); assertEquals(2, pc.beansCount()); PojoAnnBean pojoBean = pc.getBean("pojo"); SomeService ss = pc.getBean("someService"); assertNotNull(pojoBean); assertNotNull(ss); assertSame(ss, pojoBean.fservice); assertSame(ss, pojoBean.service); assertSame(ss, pojoBean.service2); assertEquals(1, pojoBean.count); }
@Test void test243() { PetiteContainer pc = new PetiteContainer(); new PetiteRegistry(pc).provider("provider").type(PetiteDemo.class).method("getOne").args().register(); }
public void defineBean(Class type, Class<? extends Scope> scopeType, WiringMode wiringMode) { definePetiteBean(null, type, scopeType, wiringMode); }
/** * Removes all petite beans of provided type. Type is not resolved for name! * Instead, all beans are iterated and only beans with equal types are removed. * @see #removeBean(String) */ public void removeBean(Class type) { // collect bean names Set<String> beanNames = new HashSet<String>(); Iterator<BeanDefinition> it = beansIterator(); while (it.hasNext()) { BeanDefinition def = it.next(); if (def.type.equals(type)) { beanNames.add(def.name); } } // remove collected bean names for (String beanName : beanNames) { removeBean(beanName); } }
@Test void testWiringMethodArguments() { PetiteContainer pc = new PetiteContainer(); pc.config().setDefaultWiringMode(WiringMode.OPTIONAL); PetiteRegistry petiteRegistry = pc.createContainerRegistry(); petiteRegistry.bean(DaDrum.class).register(); petiteRegistry.bean(Guitar.class).register(); petiteRegistry.bean(TheBand.class).register(); TheBand theBand = pc.getBean(TheBand.class); assertTrue(theBand.isBandReady()); } }
/** * Defines many parameters at once. */ public void defineParameters(Map<?, ?> properties) { for (Map.Entry<?, ?> entry : properties.entrySet()) { defineParameter(entry.getKey().toString(), entry.getValue()); } }
/** * Defines many parameters at once from {@link Props}. */ public void defineParameters(Props props) { Map<?, ?> map = new HashMap<Object, Object>(); props.extractProps(map); defineParameters(map); }
@Test void testManualDefinition2() { PetiteRegistry petiteRegistry = PetiteRegistry.of(new PetiteContainer()); petiteRegistry.bean(SomeService.class).register(); petiteRegistry.bean(PojoBean.class).name("pojo").define().register(); assertEquals(2, petiteRegistry.petiteContainer().beansCount()); petiteRegistry.wire("pojo").ctor().bind(); petiteRegistry.wire("pojo").property("service").ref("someService").bind(); petiteRegistry.wire("pojo").method("injectService").ref("someService").bind(); petiteRegistry.init("pojo").invoke(POST_INITIALIZE).methods("init").register(); PojoBean pojoBean = petiteRegistry.petiteContainer().getBean("pojo"); SomeService ss = petiteRegistry.petiteContainer().getBean("someService"); assertNotNull(pojoBean); assertNotNull(ss); assertSame(ss, pojoBean.fservice); assertSame(ss, pojoBean.service); assertSame(ss, pojoBean.service2); assertEquals(1, pojoBean.count); }
@Test void testManualDefinitionUsingAnnotations2() { PetiteContainer pc = new PetiteContainer(); PetiteRegistry.of(pc).bean(SomeService.class).register(); PetiteRegistry.of(pc).bean(PojoAnnBean.class).name("pojo").define().register(); assertEquals(2, pc.beansCount()); PojoAnnBean pojoBean = pc.getBean("pojo"); SomeService ss = pc.getBean("someService"); assertNotNull(pojoBean); assertNotNull(ss); assertSame(ss, pojoBean.fservice); assertNull(pojoBean.service); assertNull(pojoBean.service2); assertEquals(0, pojoBean.count); }
public void defineBean(Class type) { definePetiteBean(null, type, null, null); }
/** * Starts with fluent registration. */ public static PetiteRegistry of(final PetiteContainer petiteContainer) { return new PetiteRegistry(petiteContainer); }
/** * Creates {@link PetiteRegistry} helper tool for this container. */ public PetiteRegistry createContainerRegistry() { return PetiteRegistry.of(this); }
public void defineBean(String name, Class type, Class<? extends Scope> scopeType) { definePetiteBean(name, type, scopeType, null); }
public void defineBean(Class type, Class<? extends Scope> scopeType) { definePetiteBean(null, type, scopeType, null); }
public void defineBean(String name, Class type) { definePetiteBean(name, type, null, null); }
public void defineBean(String name, Class type, Class<? extends Scope> scopeType, WiringMode wiringMode) { definePetiteBean(name, type, scopeType, wiringMode); }