You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote my own mutant version of the wired dataclass dependency resolver for a project but then I started using Annotated and it seems to fit much better. This is related to #35 but I was not sure if I should continue there so I just started a new issue. I was hoping to integrate my changes here but I wasn't sure what would be the best way forward or if this approach fits with wired.
Features
accepts a function OR class with dependencies marked within Annotated using Wired()
allows attr, key or call_kwargs/call_args to further extract values from a service
resolver can be used standalone
works with dataclasses, inheritance and plain classes (needs further testing though)
Limitations
Python 3.9+ AFAIK
Converting Annotated to a normalized form might be more complicated.
Might not integrate well with static type checkers
Why
Annotated seems to work the same between function signatures and class properties which makes for a simpler API and implementation
Avoids direct interaction with dataclass fields which makes for a simpler API because there is no need to proxy the behavior of field()
The resolver can be used directly which could support pyramid view mappers.
$ hatch run python -- -m wired_services.testit
Hello there, the date and time is 2025-02-01T18:36:30.806211-08:00.
Hello again there, the date and time is 2025-02-01T18:36:30.806311-08:00.
Greetings to you! Hello Ian, the date and time is 2025-02-01T18:36:30.806448-08:00. Your lucky number is 175. And good day to you!
I wrote my own mutant version of the wired dataclass dependency resolver for a project but then I started using Annotated and it seems to fit much better. This is related to #35 but I was not sure if I should continue there so I just started a new issue. I was hoping to integrate my changes here but I wasn't sure what would be the best way forward or if this approach fits with wired.
Features
Annotated
usingWired()
attr
,key
orcall_kwargs/call_args
to further extract values from a serviceLimitations
Why
Annotated
seems to work the same between function signatures and class properties which makes for a simpler API and implementationdataclass
fields which makes for a simpler API because there is no need to proxy the behavior offield()
pyramid
view mappers.AnnotatedDependencyExtractor
in https://github.com/ianjosephwilson/wired_services/blob/main/src/wired_services/servicetools.py#L32 extracts the annotations into specifications of what to resolveDependencyResolver
in https://github.com/ianjosephwilson/wired_services/blob/main/src/wired_services/servicetools.py#L80Injector
actually injects the dependencies -- https://github.com/ianjosephwilson/wired_services/blob/main/src/wired_services/servicetools.py#L102wired_service
is the decorator that can be loaded with venusian to use the extractor, resolver and injector to construct the service.The text was updated successfully, but these errors were encountered: