protected ContainerImpl create(Map<String, Object> m){ ContainerImpl impl = new ContainerImpl(); //default constructor, instantiates internal map impl.m.putAll(m); // copy all values return impl; }
/** * @param m - storage model. Should not be modified after call. */ public ContainerImpl(Map<String, Object> m){ this.m = m; } /** A new instance with default storage model */ public static ContainerImpl createDefault() { // Storage reference is isolated return new ContainerImpl(new HashMap<>()); }
/** * Creates a {@link Container} instance. Injects static members for classes * which were registered using {@link #injectStatics(Class...)}. * * @param loadSingletons If true, the container will load all singletons * now. If false, the container will lazily load singletons. Eager loading * is appropriate for production use while lazy loading can speed * development. * @throws IllegalStateException if called more than once */ public Container create(boolean loadSingletons) { ensureNotCreated(); created = true; final ContainerImpl container = new ContainerImpl( new HashMap<Key<?>, InternalFactory<?>>(factories)); if (loadSingletons) { container.callInContext(new ContainerImpl.ContextualCallable<Void>() { public Void call(InternalContext context) { for (InternalFactory<?> factory : singletonFactories) { factory.create(context); } return null; } }); } container.injectStatics(staticInjections); return container; }