import inspect

class Provider:

    def __init__(self):
        self.nodes = {}
        self.instances = {}

    def create(self, name):
        if name not in self.nodes:
            raise MissingDependencyError(name)
        entry = self.nodes[name]
        cls = entry.cls
        deps = entry.deps
        if entry.cached and name in self.instances:
            return self.instances[name]
        resolved_deps = {dep : self.create(dep) for dep in deps}
        instance = cls(**resolved_deps)
        self.instances[name] = instance
        return instance

    def register_service(self, **kwargs):
        for name, cls in kwargs.items():
            self.nodes[name] = DependencyNode(
                cls = cls,
                cached = True
                )

    def register_object(self, **kwargs):
        for name, cls in kwargs.items():
            self.nodes[name] = DependencyNode(
                cls = cls,
                cached = False
                )

    def declare_service(self, cls):
        self.register_service(**{cls.__name__ : cls})

    def declare_object(self, cls):
        self.register_object(**{cls.__name__ : cls})

class DependencyNode:

    def __init__(self, cls, cached):
        self.cls = cls
        self.deps = self.get_deps(cls)
        self.cached = cached

    def get_deps(self, cls):
        try:
            return inspect.getargspec(cls.__init__).args[1:]
        except AttributeError:
            # no __init__ --> no dep
            return []

class MissingDependencyError(Exception):

    def __init__(self, name):
        self.name = name

    def __str__(self):
        return "Unable to locate service: {}".format(self.name)

provider = Provider()

def reset():
    global provider
    provider = Provider()

def service(cls):
    provider.declare_service(cls)

def object(cls):
    provider.declare_object(cls)

def create(clsName):
    return provider.create(clsName)

@@ -262,60 +262,8 @@
 e%5D%0D%0A
-        cls = entry.cls%0D%0A        deps = entry.deps%0D%0A
     
@@ -364,64 +364,56 @@
     
-resolved_deps = %7Bdep : 
+instance = entry.cls(**
 self.
-c
 re
-ate(dep) for dep in 
+solve(entry.
 deps
-%7D
+))
 %0D%0A  
@@ -423,40 +423,29 @@
    i
-nstance = cls(**resolved_deps)%0D%0A
+f entry.cached:%0D%0A    
     
@@ -504,24 +504,113 @@
 instance%0D%0A%0D%0A
+    def resolve(self, deps):%0D%0A        return %7Bdep : self.create(dep) for dep in deps%7D%0D%0A%0D%0A
     def regi

remove object/service duplication