Search in sources :

Example 1 with SingletonScope

use of jodd.petite.scope.SingletonScope in project jodd by oblac.

the class DefaultAppCore method startPetite.

/**
	 * Creates and initializes Petite container.
	 * It will be auto-magically configured by scanning the classpath.
	 * Also, all 'app*.prop*' will be loaded and values will
	 * be injected in the matched beans. At the end it registers
	 * this instance of core into the container.
	 */
protected void startPetite() {
    log.info("petite initialization");
    petite = createPetiteContainer();
    log.info("app in web: " + Boolean.valueOf(isWebApplication));
    if (!isWebApplication) {
        // make session scope to act as singleton scope
        // if this is not a web application (and http session is not available).
        petite.registerScope(SessionScope.class, new SingletonScope());
    }
    // load parameters from properties files
    petite.defineParameters(appProps);
    // adds a scanner bean, so it can be immediately configured from props
    petite.addBean(PETITE_SCAN, appScanner);
    // automagic configuration
    registerPetiteContainerBeans(petite);
    // add AppCore instance to Petite
    petite.addBean(PETITE_CORE, this);
    petite.addBean(PETITE_PROPS, appProps);
}
Also used : SingletonScope(jodd.petite.scope.SingletonScope)

Example 2 with SingletonScope

use of jodd.petite.scope.SingletonScope in project jodd by oblac.

the class ScopeTest method testScopeAccept.

@Test
public void testScopeAccept() {
    final PetiteContainer pc = new PetiteContainer();
    SingletonScope singletonScope = pc.resolveScope(SingletonScope.class);
    ProtoScope protoScope = pc.resolveScope(ProtoScope.class);
    SessionScope sessionScope = pc.resolveScope(SessionScope.class);
    RequestScope requestScope = pc.resolveScope(RequestScope.class);
    assertTrue(singletonScope.accept(singletonScope));
    assertTrue(singletonScope.accept(protoScope));
    assertFalse(singletonScope.accept(sessionScope));
    assertFalse(singletonScope.accept(requestScope));
    assertTrue(protoScope.accept(singletonScope));
    assertTrue(protoScope.accept(protoScope));
    assertTrue(protoScope.accept(sessionScope));
    assertTrue(protoScope.accept(requestScope));
    assertTrue(sessionScope.accept(singletonScope));
    assertTrue(sessionScope.accept(protoScope));
    assertTrue(sessionScope.accept(sessionScope));
    assertFalse(sessionScope.accept(requestScope));
    assertTrue(requestScope.accept(singletonScope));
    assertTrue(requestScope.accept(protoScope));
    assertTrue(requestScope.accept(sessionScope));
    assertTrue(requestScope.accept(requestScope));
}
Also used : ProtoScope(jodd.petite.scope.ProtoScope) SingletonScope(jodd.petite.scope.SingletonScope) SessionScope(jodd.petite.scope.SessionScope) RequestScope(jodd.petite.scope.RequestScope) Test(org.junit.Test)

Aggregations

SingletonScope (jodd.petite.scope.SingletonScope)2 ProtoScope (jodd.petite.scope.ProtoScope)1 RequestScope (jodd.petite.scope.RequestScope)1 SessionScope (jodd.petite.scope.SessionScope)1 Test (org.junit.Test)1