I'm trying to create a very simple app using the IoC framework for Fantom afIoc to become familiar with it. I tried this...
using afIoc
class Main {
Registry registry := IocService([AppModule#]).start.registry
@Inject
myPod::Version? version
Void main() {
echo("version is $version")
}
}
The Version class is
const class Version {
override Str toStr() {
"0.0.1"
}
}
The AppModule is
using afIoc
class AppModule {
static Void bind(ServiceBinder binder) {
binder.bind(myPod::Version#)
}
}
It compiles but prints version is null
. I fixed the problem by redefining my Main class:
using afIoc
class Main {
Registry registry := IocService([AppModule#]).start.registry
Void main() {
version := (myPod::Version) registry.serviceById("myPod::Version")
echo("version is $version")
}
}
But I'd like to understand the lifecycle of the afIoc Registry and why the Version service is not injected in my first version of the Main class. Can anyone explain, please?