Search in sources :

Example 1 with AutomagicPetiteConfigurator

use of jodd.petite.config.AutomagicPetiteConfigurator in project jodd by oblac.

the class DefaultAppCore method registerPetiteContainerBeans.

/**
	 * Configures Petite container. By default scans the class path
	 * for petite beans and registers them automagically.
	 */
protected void registerPetiteContainerBeans(PetiteContainer petiteContainer) {
    AutomagicPetiteConfigurator pcfg = new AutomagicPetiteConfigurator();
    appScanner.configure(pcfg);
    pcfg.configure(petiteContainer);
}
Also used : AutomagicPetiteConfigurator(jodd.petite.config.AutomagicPetiteConfigurator)

Example 2 with AutomagicPetiteConfigurator

use of jodd.petite.config.AutomagicPetiteConfigurator in project jodd by oblac.

the class PetiteWebApplication method providePetiteContainer.

/**
	 * Provides {@link PetiteContainer Petite container} instance that will be used as application context.
	 * By default it {@link #createPetiteContainer() creates new container instance} and performs
	 * {@link jodd.petite.config.AutomagicPetiteConfigurator auto-magic configuration}.
	 */
protected PetiteContainer providePetiteContainer() {
    PetiteContainer pc = createPetiteContainer();
    AutomagicPetiteConfigurator configurator = new AutomagicPetiteConfigurator();
    configurator.configure(pc);
    return pc;
}
Also used : AutomagicPetiteConfigurator(jodd.petite.config.AutomagicPetiteConfigurator) PetiteContainer(jodd.petite.PetiteContainer)

Example 3 with AutomagicPetiteConfigurator

use of jodd.petite.config.AutomagicPetiteConfigurator in project jodd by oblac.

the class WireTest method testContainer.

@Test
public void testContainer() {
    PetiteContainer pc = new PetiteContainer();
    AutomagicPetiteConfigurator configurator = new AutomagicPetiteConfigurator();
    configurator.setExcludeAllEntries(true);
    configurator.setIncludedEntries("jodd.petite.*");
    configurator.setExcludedEntries("jodd.petite.data.*", "jodd.petite.tst3.*", "jodd.petite.tst.Ses");
    configurator.setExcludedEntries("jodd.petite.data.*", "jodd.petite.tst3.*", "jodd.petite.tst.Ses", "*Public*", "*Secret*", "*$*", "jodd.petite.prox.*");
    configurator.configure(pc);
    assertEquals(1, pc.getTotalBeans());
    assertEquals(1, pc.getTotalScopes());
    assertEquals(0, Foo.instanceCounter);
    Foo foo = pc.getBean("foo");
    assertNotNull(foo);
    assertEquals(1, foo.hello());
    foo = pc.getBean("foo");
    assertEquals(1, foo.hello());
    // register again the same class, but this time with proto scope
    pc.registerPetiteBean(Foo.class, "foo2", ProtoScope.class, null, false);
    assertEquals(2, pc.getTotalBeans());
    assertEquals(2, pc.getTotalScopes());
    assertEquals(2, ((Foo) pc.getBean("foo2")).hello());
    assertEquals(3, ((Foo) pc.getBean("foo2")).hello());
    // register boo
    pc.registerPetiteBean(Boo.class, null, null, null, false);
    assertEquals(3, pc.getTotalBeans());
    assertEquals(2, pc.getTotalScopes());
    Boo boo;
    try {
        //noinspection UnusedAssignment
        boo = pc.getBean("boo");
        fail();
    } catch (PetiteException pex) {
    // zoo class is missing
    }
    // registering missing dependency.
    // however we need to remove existing bean that requires this dependency
    // as it has been already initialized.
    pc.registerPetiteBean(Zoo.class, null, null, null, false);
    pc.removeBean(Boo.class);
    pc.registerPetiteBean(Boo.class, null, null, null, false);
    assertEquals(4, pc.getTotalBeans());
    assertEquals(2, pc.getTotalScopes());
    boo = pc.getBean("boo");
    assertNotNull(boo);
    assertNotNull(boo.getFoo());
    assertNotNull(boo.zoo);
    assertSame(boo.zoo.boo, boo);
    assertEquals(3, boo.getFoo().hello());
    // '2' because the first time we getBean('boo') the wiring occurred before exception was throwed!
    assertEquals(2, boo.getFoo().getCounter());
}
Also used : AutomagicPetiteConfigurator(jodd.petite.config.AutomagicPetiteConfigurator) Test(org.junit.Test)

Example 4 with AutomagicPetiteConfigurator

use of jodd.petite.config.AutomagicPetiteConfigurator in project jodd by oblac.

the class MixedScope343Test method setupPetiteContainer.

@Before
public void setupPetiteContainer() {
    PetiteConfig petiteConfig = PetiteHelper.createPetiteConfig();
    ProxyProxetta proxyProxetta = PetiteHelper.createProxyProxetta();
    petiteContainer = new ProxettaAwarePetiteContainer(proxyProxetta, petiteConfig);
    AutomagicPetiteConfigurator petiteConfigurator = new AutomagicPetiteConfigurator();
    petiteConfigurator.setIncludedEntries(this.getClass().getPackage().getName() + ".*");
    petiteConfigurator.configure(petiteContainer);
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) ProxettaAwarePetiteContainer(jodd.petite.proxetta.ProxettaAwarePetiteContainer) PetiteConfig(jodd.petite.PetiteConfig) AutomagicPetiteConfigurator(jodd.petite.config.AutomagicPetiteConfigurator) Before(org.junit.Before)

Aggregations

AutomagicPetiteConfigurator (jodd.petite.config.AutomagicPetiteConfigurator)4 PetiteConfig (jodd.petite.PetiteConfig)1 PetiteContainer (jodd.petite.PetiteContainer)1 ProxettaAwarePetiteContainer (jodd.petite.proxetta.ProxettaAwarePetiteContainer)1 ProxyProxetta (jodd.proxetta.impl.ProxyProxetta)1 Before (org.junit.Before)1 Test (org.junit.Test)1