mixinafIoc::ServiceBuilder
afIoc::ServiceBuilder
@Js
Use to define an IoC service.
serviceBuilder := regBuilder.addService()
serviceBuilder
.withId("acme::penguins")
.withType(Penguins#)
.withImplType(PenguinsImpl#)
.withScope("root")
The above could be inlined and, taking advantage of defaults, could be shortened to just:
regBuilder.addService(Penguins#).withRootScope
- withAlias
abstract This withAlias(Str alias)Creates an alias ID that this service is also known as.
reg := regBuilder { addService(Wolf#).withAlias("acme::Sheep") }.build reg.rootScope.serviceById("acme::Wolf") reg.rootScope.serviceById("acme::Sheep")// --> same service as 'acme::wolf'- withAliasType
abstract This withAliasType(Type aliasType)Adds an alias Type that this service is also known as.
reg := regBuilder { addService(Wolf#).withAliasType(Sheep#) }.build reg.rootScope.serviceByType(Wolf#) reg.rootScope.serviceByType(Sheep#)// --> same service as Wolf- withAliasTypes
abstract This withAliasTypes(Type[]? aliasTypes)Sets many Types that this service is also known as.
- withAliases
abstract This withAliases(Str[]? aliases)Creates multiple aliases that this service is also known as.
- withBuilder
abstract This withBuilder(|Scope->Obj?? serviceBuilder)Sets a func that creates instances of the services.
regBuilder.addService(Wolf#).withBuilder |Scope scope -> Obj?| { return Penguin() }Scopeis the current scope the service is being built in.- withCtorArgs
abstract This withCtorArgs(Obj?[]? args)Set constructor arguments to be used when the service is autobuilt. Note the args must be immutable.
regBuilder.addService(Penguin#).withCtorArgs([arg1, arg2])
- withFieldVals
abstract This withFieldVals([Field:Obj?]? fieldVals)Set field values to used when the service is autobuilt. An alternative to using ctor args. Note all vals must be immutable.
regBuilder.addService(Penguin#).withFieldVals([Penguin#arg1 : "val1", Penguin#arg2 : "val2"])
- withId
Sets the unique service ID. If not set explicitly it is taken to be the qualified Type name.
regBuilder.addService.withId("thread")- withImplType
abstract This withImplType(Type? implType)Sets the implementation of the service. Used when the service is autobuilt. May also be set via
addService().regBuilder.addService(IPenguin#, PenguinImpl#) regBuilder.addService(Penguin#).withImplType(PenguinImpl#)
ImplTypeis used, along withctorArgsandfieldValsto autobuild an instance of the service.- withRootScope
abstract This withRootScope()Convenience for
withScope("root").regBuilder.addService(Wolf#).withRootScope
- withScope
abstract This withScope(Str scope)Sets the scope that the service can be created in.
regBuilder.addService(Wolf#).withScope("thread")- withScopes
abstract This withScopes(Str[]? scopes)Sets multiple scopes that the service can be created in.
regBuilder.addService(Wolf#).withScopes(["root", "thread"])
- withType
abstract This withType(Type type)Sets the type of the service. May also be set via
addService().regBuilder.addService(Penguin#) regBuilder.addService.withType(Penguin#)
If the service type is a mixin then either an implementation type or a builder must be subsequently set.
regBuilder.addService(IPenguin#).withImplType(PenguinImpl#)