Package se.jbee.inject

Examples of se.jbee.inject.Repository


      this.repositoryScope = repositoryScope;
    }

    @Override
    public <T> T serve( Demand<T> demand, Injectable<T> injectable ) {
      Repository repository = threadRepository.get();
      if ( repository == null ) {
        // since each thread is just accessing its own repo there cannot be a repo set for the running thread after we checked for null
        repository = repositoryScope.init();
        threadRepository.set( repository );
      }
      return repository.serve( demand, injectable );
    }
View Full Code Here


    }

    private static Map<Scope, Repository> initRepositories( Binding<?>[] bindings ) {
      Map<Scope, Repository> repositories = new IdentityHashMap<Scope, Repository>();
      for ( Binding<?> i : bindings ) {
        Repository repository = repositories.get( i.scope );
        if ( repository == null ) {
          repositories.put( i.scope, i.scope.init() );
        }
      }
      return repositories;
View Full Code Here

    // just for test
  }

  @Test
  public void thatDependencyTypeScopeEnsuresSingletonPerExactGenericType() {
    Repository r = Scoped.DEPENDENCY_TYPE.init();
    Demand<A> da = demand( resource( A.class ), dependency( A.class ), 1, 2 );
    Demand<B> db = demand( resource( B.class ), dependency( B.class ), 2, 2 );
    A a = new A();
    B b = new B();
    Injectable<A> ia = new ConstantInjectable<A>( a );
    Injectable<B> ib = new ConstantInjectable<B>( b );
    assertThat( r.serve( da, ia ), sameInstance( a ) );
    assertThat( r.serve( da, null ), sameInstance( a ) ); // the null Injectable shouldn't be called now
    assertThat( r.serve( db, ib ), sameInstance( b ) );
    assertThat( r.serve( db, null ), sameInstance( b ) ); // the null Injectable shouldn't be called now
  }
View Full Code Here

TOP

Related Classes of se.jbee.inject.Repository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.