annotation Athena::DependencyInjection::Autoconfigure
#
Applies the provided configuration to any registered service of the type the annotation is applied to. E.g. a module interface, or a parent type.
The following values may be auto-configured:
tags : Array(String | NamedTuple(name: String, priority: Int32?))
- The tags to apply.calls : Array(Tuple(String, Tuple(T)))
- Service calls that should be made on the service after its instantiated.bind : NamedTuple(*)
- A named tuple of values that should be available to the constructorspublic : Bool
- If the services should be accessible directly from the containerconstructor : String
- Name of a class method to use as the service factory
Tip
Checkout ADI::AutoconfigureTag
and ADI::TaggedIterator
for a simpler way of handling tags.
Example#
@[ADI::Autoconfigure(bind: {id: 123}, public: true)]
module SomeInterface; end
@[ADI::Register]
record One do
include SomeInterface
end
@[ADI::Register]
record Two, id : Int32 do
include SomeInterface
end
# The services are only accessible like this since they were auto-configured to be public.
ADI.container.one # => One()
# `123` is used as it was bound to all services that include `SomeInterface`.
ADI.container.two # => Two(@id=123)