/** * Create child container */ protected ComponentContainer(ComponentContainer parent) { this.parent = parent; this.pico = parent.pico.makeChildContainer(); this.parent.child = this; this.propertyDefinitions = parent.propertyDefinitions; this.componentKeys = new ComponentKeys(); addSingleton(this); }
Object of(Object component) { return of(component, Loggers.get(ComponentKeys.class)); }
public ComponentContainer addExtension(@Nullable PluginMetadata plugin, Object extension) { Object key = componentKeys.of(extension); try { pico.as(Characteristics.CACHE).addComponent(key, extension); } catch (Throwable t) { throw new IllegalStateException("Unable to register extension " + getName(extension), t); } declareExtension(plugin, extension); return this; }
/** * Create root container */ public ComponentContainer() { this.parent = null; this.child = null; this.pico = createPicoContainer(); this.componentKeys = new ComponentKeys(); propertyDefinitions = new PropertyDefinitions(); addSingleton(propertyDefinitions); addSingleton(this); }
/** * @param singleton return always the same instance if true, else a new instance * is returned each time the component is requested */ public ComponentContainer addComponent(Object component, boolean singleton) { Object key = componentKeys.of(component); if (component instanceof ComponentAdapter) { pico.addAdapter((ComponentAdapter) component); } else { pico.as(singleton ? Characteristics.CACHE : Characteristics.NO_CACHE).addComponent(key, component); declareExtension(null, component); } return this; }