Class ServiceDescriptor.Builder

    • Method Detail

      • setSingleton

        public ServiceDescriptor.Builder setSingleton​(boolean isSingleton)
        Sets whether to configure the service as singleton. If true, the service will only be instantiated once and all other services depending on it will share the same instance. Defaults to true.
        Parameters:
        isSingleton - true if singleton, false if not
        Returns:
        this builder
      • setConcreteType

        public ServiceDescriptor.Builder setConcreteType​(@Nullable
                                                         Class<?> concreteType)
        Sets the concrete type of the service to instantiate. It is useful when the ServiceReference is an interface or an abstract type, it allows to specify which implementation to use.
        Parameters:
        concreteType - the concrete type to set
        Returns:
        this builder
        Throws:
        IllegalArgumentException - if concreteType is not a subtype of the service class
      • setFactoryMethod

        public ServiceDescriptor.Builder setFactoryMethod​(@Nullable
                                                          Function<Class<?>,​? extends FactoryMethod> factoryMethod)
        Sets the factory method that will instantiate the service, with the potential dependencies to inject. Defaults to a constructor with no arguments (FactoryMethod.constructor())
        Parameters:
        factoryMethod - the factory method to set. The appropriate Function can be obtained by using one of the static methods of the FactoryMethod interface.
        Returns:
        this builder
      • addSetterMethod

        public ServiceDescriptor.Builder addSetterMethod​(String name,
                                                         Injectable param)
        Adds a setter method that is capable of injecting an additional dependency after instantiation.

        This method may be called multiple times for the same setter. This is useful if your setter actually represents a add operation.

        This assumes that the setter has a void return type. If it is not the case, use addSetterMethod(String, Injectable, Class) instead to specify a return type for the setter method.

        Parameters:
        name - the setter name
        param - the injectable parameter describing the dependency to inject in the setter
        Returns:
        this builder
      • addSetterMethod

        public ServiceDescriptor.Builder addSetterMethod​(String name,
                                                         Injectable param,
                                                         Class<?> returnType)
        Adds a setter method that is capable of injecting an additional dependency after instantiation.

        This method may be called multiple times for the same setter. This is useful if your setter actually represents a add operation.

        This overload allows you to specify a return type for the setter method. In most cases it will be void, if that's the case you may prefer addSetterMethod(String, Injectable) with makes this assumption.

        Parameters:
        name - the setter name
        param - the injectable parameter describing the dependency to inject in the setter
        returnType - the return type of the setter method
        Returns:
        this builder