anchor.diff:  ---
  -title: "Non Contextual Instances in CDI 2.0"
  -summary: how to use non contextual instances in CDI and what's nez in 2.0
  +title: "Non-Contextual Instances in CDI 2.0"
  +summary: how to use non-contextual instances in CDI and what's nez in 2.0
   layout: post
   authors: [asd]
   tags: [CDI,SPI,Extension]
  
positive.code: == Conclusion
  
  So we covered all the use cases for non-contextual instance creation and management in CDI.
  Keep in mind that except for `Unmanaged`, all the SPI elements shown in this post are also very useful when creating custom bean.
  `InterceptionFactory` is also very useful to apply interceptors in a producer.
negative.code: BeanManager bm;
  ----
  
  If are not CDI programming model, the easiest way to access the `BeanManager` is ot use the `CDI` class available since CDI 1.1 (note that it also works in CDI programming model even if direct injection is still preferred to static call done with `CDI.current()`).
  
  [source,java]
  ----
  BeanManager bm = CDI.current().getBeanManager();
  ----
  
  In certain circumstance, you may want to retrieve the `BeanManager` from a JNDI lookup through the `java:comp/BeanManager`, JNDI name.
  
  The following example show how to create a non-contextual instance from `MyClass` in which you need to create an injection point (add `@Inject`) on the field `MyField`
  
  [source,java]
  ----
  public void doSomethingWithContextualMyClass() {
          BeanManager bm = CDI.current().getBeanManager();  //<1>
          InjectionTargetFactory<MyClass> itf = bm
                  .getInjectionTargetFactory(bm.createAnnotatedType(MyClass.class)); //<2>
          itf.configure() //<3>
                  .filterFields(f -> "MyField".equals(f.getJavaMember().getName()))
                  .findFirst()
  