Skip to content

Migrate DI features to annotations #385

@Blacksmoke16

Description

@Blacksmoke16

The DI component currently has some features that are implemented at top level macro calls. Specifically .bind and .auto_configure. These were implemented like that for reasons, mainly not having thought of a better way, and due the increased complexity of the alternatives.

However with the introduction of #337, the DI component is a lot more robust and flexible when it comes to adding in features. As such, I propose we start to deprecate the "legacy" macros calls where possible into annotations that can be applied closer to the source.

E.g. something like:

module ConfigInterface; end

ADI.auto_configure ConfigInterface, {tags: ["config"]}

Could become:

@[ADI::Autoconfigure(tags: ["config"])]
module ConfigInterface; end

There is also room to improve how other DI features work by adding additional annotations. Service aliasing for example. Instead of:

module TransformerInterface; end

@[ADI::Register(alias: TransformerInterface)]
struct ShoutTransformer
  include TransformerInterface
end

You could do

module TransformerInterface; end

@[ADI::Register]
@[ADI::AsAlias(TransformerInterface)]
struct ShoutTransformer
  include TransformerInterface
end

This is nice not only from a readability perspective, but also from an implementation POV as it decouples the alias logic from the Register annotation itself.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions