Class DynamicClassProvider

  • All Implemented Interfaces:
    com.google.inject.Provider<java.lang.Object>, javax.inject.Provider<java.lang.Object>
    Direct Known Subclasses:
    DynamicSingletonProvider

    @Singleton
    public class DynamicClassProvider
    extends java.lang.Object
    implements com.google.inject.Provider<java.lang.Object>
    Provider allows using interfaces or abstract classes as normal guice beans. Simply annotate interface or abstract class with @ProvidedBy(DynamicClassProvider.class) and use it as usual guice bean.

    Original bean will be correctly handled by guice aop: provider will generate new class, which guice could use for proxy generation.

    If used with injectors hierarchy or within private modules, use together with GeneratorAnchorModule to properly scope dynamic bindings.

    Providers use guice package to use internal guice api (to resolve actual required type)

    Since:
    07.12.2014
    See Also:
    if you prefer direct registration in module
    • Constructor Summary

      Constructors 
      Constructor Description
      DynamicClassProvider​(com.google.inject.Injector injector)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object get()  
      protected java.lang.Class<? extends java.lang.annotation.Annotation> getScopeAnnotation()
      Override it to specify different annotation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DynamicClassProvider

        @Inject
        public DynamicClassProvider​(com.google.inject.Injector injector)
    • Method Detail

      • get

        public java.lang.Object get()
        Specified by:
        get in interface com.google.inject.Provider<java.lang.Object>
        Specified by:
        get in interface javax.inject.Provider<java.lang.Object>
      • getScopeAnnotation

        protected java.lang.Class<? extends java.lang.annotation.Annotation> getScopeAnnotation()
        Override it to specify different annotation. By default, no annotation specified which will implicitly lead to default prototype scope.
        Returns:
        scope annotation which should be applied to generated class