/** * Registers component instance and wires it with internal container. * Warning: in this moment we can not guarantee that all other components * are registered, replaced or configuration is update; therefore DO NOT * USE injection, unless you are absolutely sure it works. */ public void registerComponentInstance(final String name, final Object componentInstance) { log.debug(() -> "Madvoc WebApp component: [" + name + "] --> " + componentInstance.getClass().getName()); madpc.removeBean(name); madpc.addBean(name, componentInstance); }
/** * Registers Madvoc component with given name. */ public <T> void registerComponent(final String name, final Class<T> component, final Consumer<T> consumer) { log.debug(() -> "Madvoc WebApp component: [" + name + "] --> " + component.getName()); madpc.removeBean(name); madpc.registerPetiteBean(component, name, null, null, false, consumer); }
/** * Registers Madvoc component with given name. */ public void registerComponent(final String name, final Class component) { log.debug(() -> "Madvoc WebApp component: [" + name + "] --> " + component.getName()); madpc.removeBean(name); madpc.registerPetiteBean(component, name, null, null, false, null); }
@Test void testAutowire() { PetiteContainer pc = new PetiteContainer(); pc.registerPetiteBean(Goo.class, null, ProtoScope.class, null, false, null); pc.registerPetiteBean(Loo.class, null, null, null, false, null); assertEquals(2, pc.beansCount()); Goo goo = pc.getBean("goo"); assertNotNull(goo); assertNotNull(goo.looCustom); assertNull(goo.foo); pc.registerPetiteBean(Foo.class, null, null, null, false, null); goo = pc.getBean("goo"); assertNotNull(goo); assertNotNull(goo.looCustom); assertNull(goo.foo); pc = new PetiteContainer(); pc.config().setDefaultWiringMode(WiringMode.AUTOWIRE); pc.registerPetiteBean(Goo.class, null, ProtoScope.class, null, false, null); pc.registerPetiteBean(Loo.class, null, null, null, false, null); pc.registerPetiteBean(Foo.class, null, null, null, false, null); goo = pc.getBean("goo"); assertNotNull(goo); assertNotNull(goo.looCustom); assertNotNull(goo.foo); pc.removeBean(Goo.class); }
pc.removeBean(Boo.class); pc.registerPetiteBean(Boo.class, null, null, null, false, null);
/** * Registers component instance and wires it with internal container. */ public final void registerComponent(String name, Object componentInstance) { if (log.isDebugEnabled()) { log.debug("Registering component '" + name + "' instance of " + componentInstance.getClass().getName()); } madpc.removeBean(name); madpc.addBean(name, componentInstance); }
public final void registerComponent(String name, Class component) { if (log.isDebugEnabled()) { log.debug("Registering component '" + name + "' of type " + component.getName()); } madpc.removeBean(name); madpc.registerBean(name, component); }