import flow.interfaces
import injector
import pkg_resources

@injector.singleton
@injector.inject(i=injector.Injector)
class ServiceLocator(flow.interfaces.IServiceLocator):
    def __init__(self):
        self._services = {}
        for ep in pkg_resources.iter_entry_points('flow.services'):
            cls = ep.load()
            self._services[ep.name] = self.i.get(cls)

    def __getitem__(self, name):
        return self._services[name]

    def get(self, name, default=None):
        try:
            return self[name]
        except KeyError:
            return default

@@ -218,16 +218,59 @@
 ces = %7B%7D
+%0A%0A    def _get_missing_service(self, name):
 %0A       
@@ -327,16 +327,22 @@
 ervices'
+, name
 ):%0A     
@@ -382,47 +382,118 @@
   se
-lf._services%5Bep.name%5D = self.i.get(cls)
+rvice = self.i.get(cls)%0A            self._services%5Bep.name%5D = service%0A            break%0A        return service
 %0A%0A  
@@ -515,32 +515,49 @@
 __(self, name):%0A
+        try:%0A    
         return s
@@ -575,16 +575,92 @@
 es%5Bname%5D
+%0A        except KeyError:%0A            return self._get_missing_service(name)
 %0A%0A    de

make ServiceLocator lazy-load services