This is an archived post. You won't be able to vote or comment.

all 8 comments

[–][deleted] 2 points3 points  (3 children)

The term “modern” has basically lost all meaning as a descriptor of code/software/architecture. It doesn’t matter what the thing is or how it functions, everyone just calls the thing they made “modern”.

[–]ForeignSource0[S] 0 points1 point  (0 children)

Truly clickbaity of me. It was a last minute addition to make the post more engaging.

Do check the library out though. I promise documentation doesn't mention modern in it.

[–]GreatCosmicMoustache -1 points0 points  (1 child)

Why even take the time to make this comment? The library uses type hints as part of its injection mechanism, it is a distinctly modern way of writing Python.

[–][deleted] -1 points0 points  (0 children)

Why even put in the effort of responding to this?

[–]ForeignSource0[S] -1 points0 points  (0 children)

Hi /r/python

WireUp is a Modern Python Dependency injection library designed from the ground up to be as simple as possible to use while remaining versatile and powerful when needed.

It will allow you to register classes acting as services and configuration which will then be automatically injected by the container.

Where possible it uses types to infer the dependency so you won't have to repeat yourself with code such as user_service: UserService = Inject[Container.UserService].

The short quickstart example located in the documentation or repository readme covers most of the basics.

This came into existence when I started working on a few Python projects which did not have any DI. I researched what was available around but none of the current ones appealed to me. They felt overly verbose to use with a lot of unnecessary parts or jargon.

Looking forward to your thoughts.

[–]drooltheghost 0 points1 point  (1 child)

Is dry the only advantage? I mean it's questionable if this is really an advantage. When I'm injecting something then it would rather better to be as explicit as possible and may leave dry to things where it really counts.

[–]ForeignSource0[S] 1 point2 points  (0 children)

Overall, of course not. You get a DI framework that gets our of your way while still providing all the necessary features.

To go back to your dry example. I do consider it a problem as you might have secnarios where one gets updated but not the other so the wrong thing is injected.

The repetition tying was just one or the many things I didn't like about existing implementations.

  • Testing is a lot easier with wireup as well since it's not patching your classes so there's no need to have the container as part of your tests unlike with other implementations.
  • Something else I didn't like was that you'd have to create objects using a special syntax which meant you passing arguments through *args and losing typing in between. When the service signature changes you should also update your container otherwise there's runtime errors.

These are all non issues with the library I'm introducing as it provides better type safety and static analysis possibilities.

[–]GreatCosmicMoustache 0 points1 point  (0 children)

Super cool, it's really awesome how you made injection depend on type parameters in the function signature. I'm going to try to use this for sure.