Java Reference

Application Startup

Introduction

The most fundamental technology of the KOS SDK is the BeanContext. The BeanContext, also known simply as the "context", is a container that holds your application’s Java beans (objects), "wires" those beans together (in the preferred order), and sets up event listeners.

Overview

As a KOS application developer, you instantiate your beans and place them in this BeanContext. Once there, the container injects those objects into other dependent beans. This process is the inverse of the bean itself instantiating the objects it needs. This is known as Inversion of Control (IoC) or Dependency Injection (DI).

Java Beans

In the most general case, a Java "bean" is simply any Java object. In relation to our BeanContext, a bean is a Java object that is part of that context, and is therefore managed by the context. Since the context is aware of these managed beans, it can inject properties, invoke callback methods, etc.

This makes the BeanContext a "lightweight dependency injection engine". You might be familiar with this concept, as it is analogous to the way Spring Framework works.

Dependency Injection

To learn more, check out:

For our purposes, DI and IoC are the same thing.

Typical App

To get started, let’s see what your primary application object might look like:

MyApp class
/**
 * This is the one and only application class, where everything starts.
 */
public class MyApp extends SystemApplication<BaseAppConfig> { (1)

    /**
     * Initialize and wire all beans.
     */
    public void init() {

        // 1) Retrieve the global bean context: (2)
        BeanContext ctx = KosAdmin.ctx;

        // 2) Instantiate all of your beans: (3)
        MyClass1 myClass1 = new MyClass1();
        MyClass2 myClass2 = new MyClass2();
        MyClass3 myClass3 = new MyClass3();

        // 3) Add all of these objects to the bean context: (4)
        ctx.add(myClass1);
        ctx.add(myClass2);
        ctx.add(myClass3);

        // 4) Inject all @Autowired fields: (5)
        ctx.update();

        // . . .
    }
}
1 Define a class that extends the built-in SystemApplication
2 Retrieve the BeanContext
3 Instantiate your beans
4 Add those beans to the context
5 Wire those beans together

We’ll learn more about these topics and more in the following pages.

Summary

Before we get into the bean context though, we must first understand autowiring, which explains how beans are given their dependent objects.

After that, we’ll look at the BeanContext, which details how to write your application’s startup code.

This is followed up with the CtxEventListener, which informs our objects when beans have been injected.

And finally, we learn about Ready Processing, which alerts our beans when other dependent beans are operational.

Previous
Next
On this page
Java Development
Seamlessly transition from Legacy+ systems to Freestyle microdosing and advanced distributed dispense systems.
UI Development
Using KOS SDKs, integrating Consumer and Non-consumer facing UIs becomes seamless, giving you less hassle and more time to create.
Video Library
Meet some of our development team, as they lead you through the tools, features, and tips and tricks of various KOS tools.
Resources
Familiarize yourself with KOS terminology, our reference materials, and explore additional resources that complement your KOS journey.
Copyright © 2024 TCCC. All rights reserved.