| sigh DI is not the same as an IOC container. Get it right ffs, if you want people to take you seriously. DI: class Blah():
def __init__(self, dependency):
self.dep = depedency
IOC: my_blah = container.resolve(Blah)
Anyway, onto my main complaint: "Pinject is a pythonic dependency injection library. Python ports of other libraries, like
Spring or Guice, retain the feel (and verbosity) of being designed for a statically typed
language. Pinject was designed from the ground up for python."
Wow, I'm impressed. Designed from the ground up for python. That's why you needed ~20 pages of documentation on how to use it?Intuitive. Also, what's wrong with annotations? I'm rather fond of this sort of code: ### implements, resolve, Scope
class IType(object):
prop1 = None
def call(self):
pass
@implements(IType)
class ImplType(object):
prop1 = "Value"
def call(self):
pass
scope = Scope()
scope.register(ImplType)
@resolve(scope)
class UsesType(object):
def __init__(self, t=IType):
self.t = t
instance = UsesType()
Or in pinject: obj_graph = pinject.new_object_graph(binding_specs=[SomeBindingSpec()])
needs_provider = obj_graph.provide(NeedsProvider)
But wait, I want a test. Ok~ instance = UsesType(my_mock)
Or in pinject: ??????
In fact, pinject doesn't even mention tests in its documentation. Whew~ That's only the whole reason for using DI in the first place.Self important library is self important. Not amazed. |
That's not IOC. That's service location. Which is only used at the "composition root" (look it up) in IOC.
"In fact, pinject doesn't even mention tests in its documentation. Whew~ That's only the whole reason for using DI in the first place."
No, testing accounts for just one of the more minor reasons to be using DI.