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

Source

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

Source

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

Source

abstract This withAliasTypes(Type[]? aliasTypes)

Sets many Types that this service is also known as.

withAliases

Source

abstract This withAliases(Str[]? aliases)

Creates multiple aliases that this service is also known as.

withBuilder

Source

abstract This withBuilder(|Scope->Obj?? serviceBuilder)

Sets a func that creates instances of the services.

regBuilder.addService(Wolf#).withBuilder |Scope scope -> Obj?| {
    return Penguin()
}

Scope is the current scope the service is being built in.

withCtorArgs

Source

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

Source

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

Source

abstract This withId(Str? id)

Sets the unique service ID. If not set explicitly it is taken to be the qualified Type name.

regBuilder.addService.withId("thread")
withImplType

Source

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#)

ImplType is used, along with ctorArgs and fieldVals to autobuild an instance of the service.

withRootScope

Source

abstract This withRootScope()

Convenience for withScope("root").

regBuilder.addService(Wolf#).withRootScope
withScope

Source

abstract This withScope(Str scope)

Sets the scope that the service can be created in.

regBuilder.addService(Wolf#).withScope("thread")
withScopes

Source

abstract This withScopes(Str[]? scopes)

Sets multiple scopes that the service can be created in.

regBuilder.addService(Wolf#).withScopes(["root", "thread"])
withType

Source

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#)