picoContainer的字段注入

package test;

import static org.picocontainer.injectors.NamedFieldInjection.injectionFieldNames;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

import junit.framework.TestCase;

import org.picocontainer.DefaultPicoContainer;
import org.picocontainer.injectors.NamedFieldInjection;


public class TestAssignment
    extends TestCase
{
  static EntityManager em = Persistence.createEntityManagerFactory("x_system").createEntityManager();

  DefaultPicoContainer pico = new DefaultPicoContainer(new NamedFieldInjection());


  @Override
  protected void setUp()
      throws Exception
  {
    em.getTransaction().begin();
    pico.addComponent(em);
  }


  @Override
  protected void tearDown()
      throws Exception
  {
    em.getTransaction().commit();
  }


  public void testBatchMark()
  {
    pico.as(injectionFieldNames("em")).addComponent(A.class);
    pico.as(injectionFieldNames("em", "a")).addComponent(B.class);
    pico.as(injectionFieldNames("em", "b")).addComponent(C.class);
    C cBean = pico.getComponent(C.class);
    Collection<X> xs = new ArrayList<X>();

    cBean.someMethod("test", xs);
  }
}

你可能感兴趣的:(picocontainer)