Search in sources :

Example 1 with Container

use of io.vertigo.core.component.Container in project vertigo by KleeGroup.

the class InjectorTest method testBFail.

@Test
public void testBFail() {
    Assertions.assertThrows(DIException.class, () -> {
        final B b = DIInjector.newInstance(B.class, new Container() {

            @Override
            public boolean contains(final String id) {
                return false;
            }

            @Override
            public <T> T resolve(final String id, final Class<T> componentClass) {
                return null;
            }

            @Override
            public Set<String> keySet() {
                return Collections.emptySet();
            }
        });
        nop(b);
    });
}
Also used : B(io.vertigo.core.component.di.data.B) Container(io.vertigo.core.component.Container) Set(java.util.Set) Test(org.junit.jupiter.api.Test)

Example 2 with Container

use of io.vertigo.core.component.Container in project vertigo by KleeGroup.

the class ComponentLoader method createInstance.

/**
 * Creates a component that use the injector but adds params support.
 * @param clazz the clazz of the object to create
 * @param container the container of the known components
 * @param paramManagerOpt the optional ParamManager needed to use global params resolution
 * @param params the local params
 * @return the component created
 */
public static <T> T createInstance(final Class<T> clazz, final Container container, final Optional<ParamManager> paramManagerOpt, final Map<String, String> params) {
    Assertion.checkNotNull(paramManagerOpt);
    Assertion.checkNotNull(params);
    // ---
    final ComponentParamsContainer paramsContainer = new ComponentParamsContainer(paramManagerOpt, params);
    final Container dualContainer = new ComponentDualContainer(container, paramsContainer);
    // ---
    final T component = DIInjector.newInstance(clazz, dualContainer);
    Assertion.checkState(paramsContainer.getUnusedKeys().isEmpty(), "some params are not used :'{0}' in component '{1}'", paramsContainer.getUnusedKeys(), clazz);
    return component;
}
Also used : Container(io.vertigo.core.component.Container)

Example 3 with Container

use of io.vertigo.core.component.Container in project vertigo by KleeGroup.

the class InjectorTest method testA.

@Test
public void testA() {
    final A a = DIInjector.newInstance(A.class, new Container() {

        @Override
        public boolean contains(final String id) {
            return false;
        }

        @Override
        public <T> T resolve(final String id, final Class<T> componentClass) {
            return null;
        }

        @Override
        public Set<String> keySet() {
            return Collections.emptySet();
        }
    });
    nop(a);
}
Also used : A(io.vertigo.core.component.di.data.A) Container(io.vertigo.core.component.Container) Set(java.util.Set) Test(org.junit.jupiter.api.Test)

Aggregations

Container (io.vertigo.core.component.Container)3 Set (java.util.Set)2 Test (org.junit.jupiter.api.Test)2 A (io.vertigo.core.component.di.data.A)1 B (io.vertigo.core.component.di.data.B)1