reagento / dishka

Cute DI framework with agreeable API and everything you need
https://dishka.readthedocs.io
Apache License 2.0
407 stars 44 forks source link

component as type instead of string #218

Open RonnyPfannschmidt opened 2 months ago

RonnyPfannschmidt commented 2 months ago

in a application i'm working on, components are identified by type/type name

instead of passing them in as strings, i would like to use the type as key for consistency

Tishka17 commented 2 months ago

Components are designed to be used only for subgraphs isolation. I cannot imagine how you can use types here. Anyway, there are currently almost no limitations on what you can use as a component except that they should be hashable. Type hints say that it should be only string and it is planned to be the only guaranteed way to use them, though we are not planning to break others.

Can you, please, provide more details on how are using components? Probably, we can offer another solution or extend library for your case

RonnyPfannschmidt commented 2 months ago

im trying to use the python type of a application component instead of its name

the application is lined up that each plugin repressents a different part, and most plugins have some nested services they personally use

a small subset of plugins provide "global" services consumed by the larger "ecosystem"

Tishka17 commented 2 months ago

Ok, sounds interesting. We'll think how can we weaken requirements for a componente type without taking to much responsibility from our side

RonnyPfannschmidt commented 2 months ago

Lookup by entry point, types, strings and enums come to mind

Keeping the baseline default limited to strings and requiring some extra work for fancy components seems fair