athena-framework / athena

An ecosystem of reusable, independent components
https://athenaframework.org
MIT License
211 stars 17 forks source link

New Alias annotation #389

Closed Blacksmoke16 closed 5 months ago

Blacksmoke16 commented 5 months ago

The use case for string keys is you can do something like this:

@[ADI::Register(name: "default_router")]
@[ADI::AsAlias("router")]
class Router
end

To have a service with an internal default_router id, but alias it to a more general router id. Then dependencies can be wired up to depend upon the "@router" implementation. This would allow users to in theory override the router alias to their own implementation (assuming it implements same API/interface(s)), and everything would just pick up on that w/o having to touch the original default_router. I could see this being useful at some point.

Resolves part of #385.