Skip to content

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 constructors
  • public : Bool - If the services should be accessible directly from the container
  • constructor : String - Name of a class method to use as the service factory


Checkout ADI::AutoconfigureTag and ADI::TaggedIterator for a simpler way of handling tags.


@[ADI::Autoconfigure(bind: {id: 123}, public: true)]
module SomeInterface; end

record One do
  include SomeInterface

record Two, id : Int32 do
  include SomeInterface

# The services are only accessible like this since they were auto-configured to be public. # => One()

# `123` is used as it was bound to all services that include `SomeInterface`.
ADI.container.two # => Two(@id=123)