const mixinafIoc::Registry
afIoc::Registry
(Service) - The registry of IoC services; this is the main IoC service.
- autobuild
abstract Obj autobuild(Type type, Obj?[] ctorArgs := Obj#.emptyList(), [Field:Obj?]? fieldVals := null)
Autobuilds an instance of the given type, resolving all dependencies:
- create instance via ctor marked with
@Inject
or the ctor with the most parameters - inject dependencies into fields (of all visibilities) marked with
@Inject
- call any methods annotated with
@PostInjection
ctorArgs
(if provided) will be passed as arguments to the first parameters in the autobuild ctor. Handy when you wish the ctor to take a mixture of plain objects and services. e.g. for a fwt::Command:registry.autobuild(MySaveCommand#, [entityToSave]) ... class MySaveCommand { @Inject private EntityDao entityDao private Entity entity new make(Entity entity, OtherService service, |This| injectInto) { injectInto(this) // ioc to inject all fields service.doSomething // this service is only used here, so doesn't need to be a field entityDao.save(entity) // use the field service and passed in entity } }
Note: the passed in parameters must be first in the ctor parameter list.
Impl note: A list is used rather than splats so
nulls
can be passed in.fieldVals
set (and potentially overwrite) the value of any const fields set by an it-block function.- create instance via ctor marked with
- callMethod
abstract Obj? callMethod(Method method, Obj? instance, Obj?[] providedMethodArgs := Obj#.emptyList())
Calls the method, dependency injecting the parameters.
instance
can benull
if calling a static method.The optional
providedMethodArgs
are used as method arguments. Any args not provided are dependency injected; unless they have a default argument, in which case nothing is passed in and the default is used.@since 1.5.0
- createProxy
abstract Obj createProxy(Type mixinType, Type? implType := null, Obj?[] ctorArgs := Obj#.emptyList(), [Field:Obj?]? fieldVals := null)
A companion method to
autobuild
. Creates an instance of the given mixin, which creates the real instance whenever a mixin method is invoked.If
implType
is null then it is assumed to have the same name as the mixin, plus aImpl
suffix. @since 1.5.0- dependencyByType
abstract Obj? dependencyByType(Type dependencyType, Bool checked := true)
Locates a dependency of the given type.
- injectIntoFields
abstract Obj injectIntoFields(Obj service)
Injects services and dependencies into fields (of all visibilities) marked with
@Inject
.Returns the object passed in for method chaining.
Note usage of this method is discouraged, it is far better practice for the creator to call
autobuild
instead.- serviceById
abstract Obj serviceById(Str serviceId)
Obtains a service via its unique service id.
- shutdown
abstract This shutdown()
Shuts down the Registry. Notifies all listeners that the registry has shutdown. Further method invocations on the Registry are no longer allowed, and the Registry instance should be discarded.
- startup
abstract This startup()
Invoke to execute all contributions to the RegistryStartup service.