annotation Athena::DependencyInjection::Autoconfigure

Overview

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:

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)

Defined in:

annotations.cr