org.glassfish.hk2
Interface Factory<T>

All Known Subinterfaces:
Creator<T>, Factory<T>, Holder<T>, Inhabitant<T>
All Known Implementing Classes:
AbstractCreatorImpl, AbstractCreatorInhabitantImpl, AbstractInhabitantImpl, ConfigBean, ConstructorCreator, CreatorImpl, Dom, EventPublishingInhabitant, ExistingSingletonInhabitant, Holder.Impl, InhabitantImpl, LazyInhabitant, ScopedInhabitant

Deprecated.

@Deprecated
public interface Factory<T>

Provides an instance of T either by creating a new one at each request or by returning an existing one.

Factories are used in a wide variety of ways in HK2:

  • Developers use Factories while programmatically binding services via methods line NamedBinder.toFactory(Factory). this factory is called at runtime whenever a consumer locates this factory provider and attempts to use it. The Scope of services it produces is ultimately determined by how the implementation behaves when asked to provide service instances to the consumer (i.e., the factory methods are invoked on it).

    HK2 uses Factories internally:

  • For services declared as "PerLookup", HK2 will create a Factory that will return a new service for each and every call to get() regardless of the caller context.
  • For services declared as Singleton Scope, HK2 will return the same service globally for every request made.
  • HK2 does not yet support JSR-299/330 "Dependent" services. Dependent scoped services are similar in nature to PerLookup. The similarity is that they both always return new, unique instances for every call and/or injection point being satisfied. The difference, however, relates to the lifecycle of the created component/service. PerLookup services are NOT tied to the lifecycle of the parent when used with injection. In another words, Releasable.release() will not be invoked on a PerLookup scoped service. A Dependent service in JSR-330/299, on the other hand, will be released when its parent component/service/bean is released (i.e., goes out of scope).

    Author:
    Jerome Dochez, Jeff Trent, Mason Taube

    Method Summary
     T get()
              Deprecated. The system calls this method to obtain a reference to the component/service.
     

    Method Detail

    get

    T get()
          throws ComponentException
    Deprecated. 
    The system calls this method to obtain a reference to the component/service.

    Returns:
    null is a valid return value. This is useful when a factory primarily does a look-up and it fails to find the specified component, yet you don't want that by itself to be an error. If the injection wants a non-null value (i.e., @Inject(optional=false)).
    Throws:
    ComponentException - If the factory failed to get/create an instance and would like to propagate the error to the caller.


    Copyright © 2013 Oracle Corporation. All Rights Reserved.