classafIoc::Configuration
sys::Obj afIoc::Configuration
Passed into module contribution methods to allow the method to contribute configuration.
The service defines the type of contribution by declaring a parameterised list or map in its ctor or builder method. Contributions must be compatible with the type.
@since 1.7.0
- add
@
Operator
This add(Obj value, Str? constraints := null)Adds a value to the service configuration with optional ordering constraints.
Because the keys of added values are unknown, they cannot be overridden. For that reason it is advised to use
set()
instead.value
is coerced to the service's contribution type.- addPlaceholder
This addPlaceholder(Str key, Str? constraints := null)
Adds a placeholder. Placeholders are empty configurations used to aid ordering of actual values:
config.placeholder("end") config.set("wot", ever, ["BEFORE: end"]) config.set("last", last, ["AFTER: end"])
Placeholders do not appear in the the resulting configuration and is never seen by the end service.
- autobuild
Obj autobuild(Type type, Obj?[]? ctorArgs := null, [Field:Obj?]? fieldVals := null)
A convenience method that instantiates an object, injecting any dependencies. See Registry.autobuild.
- overrideValue
This overrideValue(Obj existingKey, Obj? newValue, Str? newConstraints := null, Obj? newKey := null)
Overrides and replaces a contributed value. The existing key must exist.
existingKey
is the id / key of the value to be replaced. It may have been initially provided byset()
or have be thenewKey
of a previous override.newKey
does not appear in the the resulting configuration and is never seen by the end service. It is only used as reference to this override, so this override itself may be overridden. 3rd party libraries, when overriding, should always supply anewKey
.newKey
may be defined asObj
but sane and level headed people will always pass in aStr
.newValue
is coerced to the service's contribution type.- registry
Registry registry()
A convenience method that returns the IoC Registry.
- remove
This remove(Obj existingKey, Obj? newKey := null)
A special kind of override whereby, should this be the last override applied, the value is removed from the configuration.
existingKey
is the id / key of the value to be replaced. It may have been initially provided byset()
or have be thenewKey
of a previous override.newKey
does not appear in the the resulting configuration and is never seen by the end service. It is only used as reference to this override, so this override itself may be overridden. 3rd party libraries, when overriding, should always supply anewKey
.newKey
may be defined asObj
but sane and level headed people will always pass in aStr
.- set
@
Operator
This set(Obj key, Obj? value, Str? constraints := null)Sets a key / value pair to the service configuration with optional ordering constraints.
The constraints string is a CSV list. Each value must start with the prefix
BEFORE:
orAFTER:
.config["Breakfast"] = eggs config["Dinner"] = pie config.set("Lunch", ham, "AFTER: breakfast, BEFORE: dinner")
If the configuration uses non-Str keys, then use
key.toStr()
in the constraint strings.If the end service configuration is a List, then the keys are discarded and only the values passed in. Typically,
Str
keys are used in these situations, for ease of use.Configuration contributions are ordered across modules.
key
andvalue
are coerced to the service's contribution type.