const mixinafIoc::Registry

afIoc::Registry

@Js

(Service) - The top level IoC object that holds service definitions and the root scope.

The Registry instance may be dependency injected.

activeScope

Source

abstract Scope activeScope()

Returns the current active scope.

defaultScope

Source

abstract Scope defaultScope()

Returns the global default scope. This is the default scope used in any new thread and defaults to the root scope.

For normal IoC usage, consider using activeScope() instead.

getGlobal

Source

static Registry? getGlobal(Bool checked := true)

Returns the global Registry instance for this application. A global Registry lets class instances create / inject themselves; handy for when the IoC Container is not accessible

class MyClass {
    @Inject MyService myService

    // private it-block ctor for IoC instantiation
    private new makeViaItBlock(|This| f) { f(this) }

    // public static ctor that creates itself via the global Registry 
    static new make() {
        Registry.getGlobal.activeScope.build(MyClass#)
    }
}

Now when you create an instance of MyClass it comes fully loaded with injected services. Just don't forget to set a global Registry instance first.

registry := RegistryBuilder() { .... }.build
registry.setAsGlobal

...

// myClass now comes fully loaded with injected services
myClass := MyClass()

See setAsGlobal.

printBanner

Source

abstract Str printBanner()

Returns the Alien-Factory ASCII art banner. This is logged to standard out at registry startup. Remove the startup contribution to prevent the logging:

regBuilder.onRegistryStartup() |Configuration config| {
    config.remove("afIoc.logBanner")
}
printServices

Source

abstract Str printServices()

Returns a pretty printed list of service definitions. This is logged to standard out at registry startup. Remove the startup contribution to prevent the logging:

regBuilder.onRegistryStartup() |Configuration config| {
    config.remove("afIoc.logServices")
}
rootScope

Source

abstract Scope rootScope()

Returns the root scope.

For normal IoC usage, consider using activeScope() instead.

scopeDefs

Source

abstract Str:ScopeDef scopeDefs()

Returns a map of all defined scopes, keyed by scope ID.

serviceDefs

Source

abstract Str:ServiceDef serviceDefs()

Returns a map of all defined services, keyed by service ID.

setActiveScope

Source

abstract Void setActiveScope(Scope? activeScope)

Advanced use only.

Sets the given scope as the active scope in this thread. Call Scope.destroy() to pop this scope off the active stack, or pass null to this method to clear the active stack.

setAsGlobal

Source

abstract This setAsGlobal()

Sets the global Registry instance. (In essence, this just sets a static field to this Registry instance.)

To make sure the JVM is only running the one IoC container, this method throws an Err if the global instance has already been set.

See getGlobal

setDefaultScope

Source

abstract Scope setDefaultScope(Scope defaultScope)

Advanced use only.

Sets a new global default scope and returns the old one. Only non-threaded scopes may be set as the global default.

shutdown

Source

abstract This shutdown()

Destroys all active scopes and shuts down the registry.