Class TinyDI.Config

  • Enclosing class:
    TinyDI

    public static class TinyDI.Config
    extends java.lang.Object
    TinyDI's configuration helper.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TinyDI.Config aggressiveEncapsulationCircumventing​(boolean useEncapsulationCircumventing)
      Activates more aggressive encapsulation circumventing for Java version 16 or later.
      TinyDI.Config basePackages​(java.lang.String... basePackages)
      Specifies 1 or more fully-qualified base packages for recursive scanning.
      TinyDI configure()
      Locks TinyDI's configuration and returns the configured instance.
      java.lang.String configureForStaticScan()
      Configures wrapped TinyDI instance for the only purpose of producing static JSON result of the scanned class path and the found elements suitable for DI.
      TinyDI.Config ignoredBasePackages​(java.lang.String... ignoredBasePackages)
      Specifies 1 or more fully-qualified base packages to be excluded during recursive scanning.
      TinyDI.Config ignoredClasses​(java.lang.String... ignoredClasses)
      Specifies 1 or more fully-qualified classes to be excluded during recursive scanning.
      TinyDI.Config overrideClasspath​(java.lang.String... overridingClasspaths)
      Specifies 1 or more fully-qualified classpaths to be used during recursive scanning.
      TinyDI.Config records​(Recorded... records)
      Includes arbitrary, unannotated object instances for injection.
      TinyDI.Config staticScan​(@NonNull java.io.InputStream jsonSource, @NonNull java.lang.String encoding)
      Specifies static, serialized in JSON format classpath scan to be used during the DI process
      TinyDI.Config staticScan​(@NonNull java.lang.String json)
      Specifies static, serialized in JSON format classpath scan to be used during the DI process.
      TinyDI.Config withEnvironment​(java.lang.String[] args, java.util.Map<java.lang.String,​java.lang.String> environmentVars, java.util.Properties envProps)
      Registers custom command line arguments, environment parameters, and properties entirely substituting the detected.
      • Methods inherited from class java.lang.Object

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

      • staticScan

        public TinyDI.Config staticScan​(@NonNull
                                        @NonNull java.io.InputStream jsonSource,
                                        @NonNull
                                        @NonNull java.lang.String encoding)
        Specifies static, serialized in JSON format classpath scan to be used during the DI process
        Parameters:
        jsonSource - Valid JSON file resource containing the serialized classpath scan result.
        encoding - The charset encoding of the JSON. See StandardCharsets.
        Returns:
        The belonging instance for fluent config.
        Throws:
        java.lang.IllegalArgumentException - If configure() has been called previously.
      • staticScan

        public TinyDI.Config staticScan​(@NonNull
                                        @NonNull java.lang.String json)
        Specifies static, serialized in JSON format classpath scan to be used during the DI process.
        Parameters:
        json - A JSON string with the serialized classpath scan result.
        Returns:
        The belonging instance for fluent config.
        Throws:
        java.lang.IllegalArgumentException - If configure() has been called previously.
      • records

        public TinyDI.Config records​(Recorded... records)
        Includes arbitrary, unannotated object instances for injection. They have to be bound dynamically with @Recorded annotation though. To accomplish that see TinyDynamicDI.
        Parameters:
        records - One or more records to add.
        Returns:
        The belonging instance for fluent config.
        Throws:
        java.lang.IllegalArgumentException - If configure() has been called previously.
      • basePackages

        public TinyDI.Config basePackages​(java.lang.String... basePackages)
        Specifies 1 or more fully-qualified base packages for recursive scanning. Real JVM bytecode must be present.
        Parameters:
        basePackages - One or more fully-qualified base package names.
        Returns:
        The belonging instance for fluent config.
        Throws:
        java.lang.IllegalArgumentException - If configure() has been called previously.
      • ignoredBasePackages

        public TinyDI.Config ignoredBasePackages​(java.lang.String... ignoredBasePackages)
        Specifies 1 or more fully-qualified base packages to be excluded during recursive scanning. Real JVM bytecode must be present.
        Parameters:
        ignoredBasePackages - One or more fully-qualified base package names.
        Returns:
        The belonging instance for fluent config.
        Throws:
        java.lang.IllegalArgumentException - If configure() has been called previously.
      • ignoredClasses

        public TinyDI.Config ignoredClasses​(java.lang.String... ignoredClasses)
        Specifies 1 or more fully-qualified classes to be excluded during recursive scanning. Real JVM bytecode must be present.
        Parameters:
        ignoredClasses - One or more fully-qualified class names.
        Returns:
        The belonging instance for fluent config.
        Throws:
        java.lang.IllegalArgumentException - If configure() has been called previously.
      • overrideClasspath

        public TinyDI.Config overrideClasspath​(java.lang.String... overridingClasspaths)
        Specifies 1 or more fully-qualified classpaths to be used during recursive scanning. They override the automatically detected classpath. The module path won't be scanned in this case.
        Parameters:
        overridingClasspaths - One or more fully-qualified class paths.
        Returns:
        The belonging instance for fluent config.
        Throws:
        java.lang.IllegalArgumentException - If configure() has been called previously.
      • withEnvironment

        public TinyDI.Config withEnvironment​(java.lang.String[] args,
                                             java.util.Map<java.lang.String,​java.lang.String> environmentVars,
                                             java.util.Properties envProps)
        Registers custom command line arguments, environment parameters, and properties entirely substituting the detected.
        Parameters:
        args - Command line arguments. By default an empty array.
        environmentVars - Environment variables. By default obtained via System.getenv().
        envProps - Environment properties. By default obtained via System.getProperties().
        Returns:
        The belonging instance for fluent config.
        Throws:
        java.lang.IllegalArgumentException - If configure() has been called previously.
      • aggressiveEncapsulationCircumventing

        public TinyDI.Config aggressiveEncapsulationCircumventing​(boolean useEncapsulationCircumventing)
        Activates more aggressive encapsulation circumventing for Java version 16 or later. The hack relies on additional libraries which must be manually added as a dependency - either Narcissus or ToolFactory JVM Driver.
        Parameters:
        useEncapsulationCircumventing - Set to true to activate the aggressive hack, and use false to deactivate it
        Returns:
        The belonging instance for fluent config.
        Throws:
        java.lang.IllegalArgumentException - If configure() has been called previously.
      • configure

        public TinyDI configure()
        Locks TinyDI's configuration and returns the configured instance.
        Returns:
        Configured TinyDI instance.
      • configureForStaticScan

        public java.lang.String configureForStaticScan()
        Configures wrapped TinyDI instance for the only purpose of producing static JSON result of the scanned class path and the found elements suitable for DI. Can be used to gather the needed for DI information during the build time which can speed up the execution and allow TinyDI to work on environments with limited reflection capabilities like Android and GraalVM native images. See com.github.zhgzhg.tinydi.build.BuildTimeScan utility for more information.
        Returns:
        JSON string with the found elements of interest