/** * Starts with bean registration. Example: * <code>bean(Foo.class).name("").scope(...).wiringMode(...).define().register();</code> * * @see PetiteBeans#registerPetiteBean(Class, String, Class, WiringMode, boolean, Consumer) */ public BeanRegister bean(final Class beanType) { return new BeanRegister(beanType); }
@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 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 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); }
/** * Starts with bean registration. Example: * <code>bean(Foo.class).name("").scope(...).wiringMode(...).define().register();</code> * * @see PetiteBeans#registerPetiteBean(Class, String, Class, WiringMode, boolean, Consumer) */ public BeanRegister bean(final Class beanType) { return new BeanRegister(beanType); }
@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()); } }