Example #1
0
 def __init__(self,
              cls,
              name=None,
              lazy=False,
              singleton=True,
              service=True,
              checkRegistered=True):
     self.checkRegistered = True
     self.cls = cls
     self.qualifier_tree = scopeTools.getClassTreeQualifiers(cls)
     if name:
         name = getBean_qualifier(name)
         if name not in self.qualifier_tree:
             self.qualifier_tree.append(name)
     self.lazy = lazy
     self.singleton = singleton
     self.service = service
     if not singleton and service:
         raise Exception(
             "Error, cannot initialize service as non singleton")
Example #2
0
 def test_GetBeanName(self):
     dep2 = getBean_qualifier(Dependency2)
     self.assertEqual(dep2, 'Dependency2')
Example #3
0
 def registerInstance(self, name, instance):
     qualifier = getBean_qualifier(name)
     suitableQualifier = self._beans.find_suitable_qualifier(qualifier)
     logging.debug("Suitable qualifier for {} is: {}".format(
         qualifier, suitableQualifier))
     self._singletons.register(suitableQualifier, instance)
Example #4
0
 def getInstances(self, qualifier: typing.Type[T]) -> typing.List[T]:
     with self.lock:
         beans = self._beans.find_by_qualifier_name(
             getBean_qualifier(qualifier))
         beans = map(lambda x: self.getInstance(x), beans)
         return list(beans)
Example #5
0
 def getInstance(self, name: typing.Type[T]) -> T:
     with self.lock:
         return self._getInstance(getBean_qualifier(name))