org.glassfish.hk2
Class HK2

java.lang.Object
  extended by org.glassfish.hk2.HK2

public class HK2
extends Object

Entry point to the HK2 services runtime. Users should start with get() to get an implementation of the HK2 runtime.

Author:
Jerome Dochez

Constructor Summary
HK2(HK2Provider provider)
          Provides an HK2 APIs implementation using the provided HK2Provider instance as the implementation backend.
 
Method Summary
 Services create(Services parent, Class<? extends Module>... moduleTypes)
          Creates a new Services instances to register and lookup services to and from.
 Services create(Services parent, Module... modules)
          Creates a new Services instances to register and lookup services to and from.
static HK2 get()
          Entry point to the HK2 public APIs, will initialize the implementation and return a valid instance that can be used to configure modules bindings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HK2

public HK2(HK2Provider provider)
Provides an HK2 APIs implementation using the provided HK2Provider instance as the implementation backend. This is a very advanced usage pattern when HK2Provider implementations are customized to provide specific domain features.

Parameters:
provider - the HK2 public APIs implementation backend.
Method Detail

get

public static HK2 get()
Entry point to the HK2 public APIs, will initialize the implementation and return a valid instance that can be used to configure modules bindings. Implementation will be searched using the META-INF/services service location feature ServiceLoader for further reference.

Returns:
a HK2 instance to configure Module types or instances with or null if an implementation cannot be found.
Throws:
RuntimeException - if an implementation cannot be instantiated.

create

public Services create(Services parent,
                       Class<? extends Module>... moduleTypes)
Creates a new Services instances to register and lookup services to and from. Module will be instantiated in the order of the their declaration unless some modules have explicit dependencies on other modules through a Inject annotation. Module are components and will follow normal HK2 activation and injection procedure prior to the Module.configure(BinderFactory) call. Module that are named using the Service.name() annotation attribute will be added to the returned Services instance under the name + Module contract identity. The returned Services instance will also be registered using the optional Module name if present. Returned instance of Services is not automatically added to the parent (if not null) as an indexed Services instances. Users should use the parent's Services.bindDynamically() method to register children services.

Parameters:
parent - the parent Services instances to delegate lookup to.
moduleTypes - array of Module types that will be configured with in the returned Services instance.
Returns:
a Services instance configured with all the Module services

create

public Services create(Services parent,
                       Module... modules)
Creates a new Services instances to register and lookup services to and from. Module instances will not be injected before the Module.configure(BinderFactory) call. Returned instance of Services is not automatically added to the parent (if not null) as an indexed Services instances. Users should use the parent's Services.bindDynamically() method to register children services.

Parameters:
parent - the parent Services instances to delegate lookup to.
modules - array of Module that will be configured with in the returned Services instance.
Returns:
a Services instance configured with all the Module services


Copyright © 2012 Oracle Corporation. All Rights Reserved.