Interface Module.ModuleBeanBuilder<P,T>

Type Parameters:
P - the type provided by the bean to build
T - the actual type of the bean to build
All Superinterfaces:
Module.BeanBuilder<T,Module.ModuleBeanBuilder<P,T>>
Enclosing class:
Module

protected static interface Module.ModuleBeanBuilder<P,T> extends Module.BeanBuilder<T,Module.ModuleBeanBuilder<P,T>>

A BeanBuilder for creating module Module.Bean instances.

A module Module.Bean instance is built from a Supplier which is used to defer the actual instantiation of the bean. Initialization and destruction operations are invoked once the bean instance has been created (after dependency injection) and before its destruction respectively.


 this.bean = ModuleBeanBuilder
     .singleton("bean", () -> {
          BeanA beanA = new BeanA(serviceSocket.get());
          return beanA;
      })
      .init(BeanA::init)
      .destroy(BeanA::destroy)
      .build(this);
 
Since:
1.0
Author:
Jeremy Kuhn
See Also:
  • Method Details

    • singleton

      static <T> Module.ModuleBeanBuilder<T,T> singleton(String beanName, Supplier<T> constructor)

      Returns a singleton module bean builder.

      Singleton Module.Beans are useful when one single instance of a bean should be injected through the application.

      Type Parameters:
      T - the type of the bean to build
      Parameters:
      beanName - the bean name
      constructor - the bean instance supplier
      Returns:
      a singleton Bean Builder
    • prototype

      static <T> Module.ModuleBeanBuilder<T,T> prototype(String beanName, Supplier<T> constructor)

      Returns a prototype module bean builder.

      Prototype Module.Beans are useful when distinct instances of a bean should be injected though the application.

      Type Parameters:
      T - the type of the bean to build
      Parameters:
      beanName - the bean name
      constructor - the bean instance supplier
      Returns:
      a prototype Bean Builder
    • build

      Module.Bean<P> build()

      Builds the bean.

      Returns:
      a bean
    • override

      <P> Module.ModuleBeanBuilder<P,T> override(Optional<Supplier<P>> override)

      Specifies an override that, when present, provides bean instances instead of the builder.

      Type Parameters:
      P - the type provided by the bean to build
      Parameters:
      override - an optional override
      Returns:
      this builder