annotation Athena::DependencyInjection::TaggedIterator

Overview

Can be applied to a collection parameter to provide all the services with a specific tag. Supported collection types include: Indexable, Enumerable, and Iterator. Accepts an optional tag name as the first positional parameter, otherwise defaults to the FQN of the type within the collection type's generic.

TIP: This type is best used in conjunction with ADI::AutoconfigureTag.

The provided type lazily initializes the provided services as they are accessed.

Example

@[ADI::Register]
class Foo
  # Inject all services tagged with `"some-tag"`.
  def initialize(@[ADI::TaggedIterator("some-tag")] @services : Enumerable(SomeInterface)); end
end

@[ADI::Register]
class Bar
  # Inject all services tagged with `"SomeInterface"`.
  def initialize(@[ADI::TaggedIterator] @services : Enumerable(SomeInterface)); end
end

Defined in:

annotations.cr