Basic example

Create an object with an injectable field and use DependencyInjector to set the field value.

Example 3. Basic example

Import sodaware.blitzmax_injection

' Create a type to be injected.
Type SomeObject
    Field name:String
End Type

' Create a type to inject into.
Type MyType
    Field someValue:SomeObject    { injectable }

    Method New()
        ' Register this object as having injectable fields.
        DependencyInjector.addInjectableFields(Self)
    End Method
End Type

' Create the object to be injected.
Local toInject:SomeObject = New SomeObject
toInject.name = "To inject"

' Create the object that will be injected.
Local target:MyType = new MyType
' => target.someValue = Null

' Run the injection.
DependencyInjector.injectAll(target, [toInject])

' Check the field got set.
Print target.someValue.name
' => "To inject"