MobileUI LogoMobileUI
/

Setting up MobileUI Inject

Get started with Dependency Injection in your MobileUI project


MobileUI Inject PURPLE is the Dependency Injection Framework for MobileUI that is based on Micronaut. Follow this guide, to set it up for your MobileUI project.

Note: Since version 0.5.1, you can add MobileUI Inject to newly created MobileUI projects via the project wizard. This guide describes adding it to an existing MobileUI project.

  • 1

    To work with MobileUI Inject, you need MobileUI Purple Edition PURPLE. Currently, you get this edition by applying for our Beta-Program. You can find more information on this on the MobileUI Web Page.

  • 2

    Add the MobileUI Inject as plugin to your MobileUI project

    Inject has a runtime component, that is made available to all project modules by adding it as plugin. Find the following section in the root project's build.gradle file and add the line to the mobileuiPlugins array as shown below:

    [your-project-path]/build.gradle
    allprojects {
        ext {
            //versions are examples
            mobileuiVersion = "0.5.1"
            roboVMVersion = "2.3.9"
    
            mobileuiPlugins = [
                    "io.nevernull:mobileui-inject:$mobileuiVersion",        ]
        }
    }

    Hint: MobileUI Inject and the underlying Micronaut ApplicationContext are automatically initialized, when mobileui-inject is added to the classpath.

  • 3

    Add the MobileUI Inject Compiler to all app modules:

    The MobileUI Inject Compiler is responsible for generating the code that is required for the dependency injection. It is an annotation processor that needs to be added to all modules of your project. Add the following dependency to the modules' build.gradle files as shown below. Please make sure to follow the Java- and Kotlin-specific listing by switching to your preferred language:

    app-common/build.gradle & app-android/build.gradle & app-ios/build.gradle
    dependencies {    
        // add the annotation processor in all build files
        annotationProcessor "io.nevernull:mobileui-inject-compiler:$mobileuiVersion"}
  • Ready to inject!

    You are now ready to go. Please let Android Studio refresh the gradle information and run your apps on both platforms to check, whether everything works.

Now, inject all the things!