classafIoc::ServiceDefinitions
sys::Obj afIoc::ServiceDefinitions
Passed to AppModule
defineServices()
methods to add and override service definitions.
Service builder methods are the default means to define services. But if your service can be autobuilt
(and most can!) then the defineServices()
method is a quick and easy alternative.
If your service is a class named MyServiceClass
then it may be defined as follows:
class AppModule { static Void defineServices(ServiceDefinitions defs) { defs.add(MyServiceClass#) } }
If your service is a mixin with a default implementation class then it may be defined as follows:
static Void defineServices(ServiceDefinitions defs) { defs.add(MyService#, MyServiceImpl#) }
If the implementation class has the same name as the mixin but with an Impl
suffix (as does the example above) then it may be defined with the shorthand notation of:
static Void defineServices(ServiceDefinitions defs) { defs.add(MyService#) }
Note that the default service id for all services is the qualified name of the first parameter.
@since 2.0.0
- add
ServiceDefinitionOptions add(Type serviceType, Type? serviceImplType := null)
Defines a service of the given type. The service defaults to the following attributes:
- id - the qualified name of the service type
- scope -
perApplication
, orperThread
if the service type is non-const - proxy -
ifRequried
All options may be refined in the returned
ServiceDefinitionOptions
.- overrideById
ServiceOverrideOptions overrideById(Str id)
Override values in an existing service definition.
The given id may be a service id to override a service, or an override id to override an override.
- overrideByType
ServiceOverrideOptions overrideByType(Type serviceType)
Override values in an existing service definition.
Convenience for
overrideById(serviceType.qname)
.