-
Notifications
You must be signed in to change notification settings - Fork 10
Description
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
AnnotatedusingWired() - allows
attr,keyorcall_kwargs/call_argsto 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
Annotatedseems to work the same between function signatures and class properties which makes for a simpler API and implementation- Avoids direct interaction with
dataclassfields which makes for a simpler API because there is no need to proxy the behavior offield() - The resolver can be used directly which could support
pyramidview 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 resolve
DependencyResolver in https://github.com/ianjosephwilson/wired_services/blob/main/src/wired_services/servicetools.py#L80
Injector actually injects the dependencies -- https://github.com/ianjosephwilson/wired_services/blob/main/src/wired_services/servicetools.py#L102
wired_service is the decorator that can be loaded with venusian to use the extractor, resolver and injector to construct the service.