Exemplo n.º 1
0
 def get(self, key, provider):
     try:
         return self._locals.scope[key]
     except KeyError:
         provider = InstanceProvider(provider.get())
         self._locals.scope[key] = provider
         return provider
Exemplo n.º 2
0
 def get(self, key, provider):
     try:
         return self._locals.scope[key]
     except KeyError:
         provider = InstanceProvider(provider.get())
         self._locals.scope[key] = provider
         return provider
    def configure(self, binder):

        binder.bind(guiinjectorkeys.EVENT_CROSS_REFERENCES_FACTORY_KEY,
                    ClassProvider(EventCrossReferencesWidgetFactory),
                    scope=singleton)
        binder.bind(guiinjectorkeys.DOCUMENT_EVENT_REFERENCES_FACTORY_KEY,
                    ClassProvider(DocumentEventReferencesWidgetFactory),
                    scope=singleton)
        binder.bind(guiinjectorkeys.EVENT_DOCUMENT_REFERENCES_FACTORY_KEY,
                    ClassProvider(EventDocumentReferencesWidgetFactory),
                    scope=singleton)
        binder.bind(guiinjectorkeys.DOCUMENT_FILE_REFERENCES_FACTORY_KEY,
                    ClassProvider(DocumentFileReferencesWidgetFactory),
                    scope=singleton)
        binder.bind(guiinjectorkeys.EVENT_TYPE_REFERENCES_FACTORY_KEY,
                    ClassProvider(EventTypeReferencesWidgetFactory),
                    scope=singleton)
        binder.bind(guiinjectorkeys.EVENT_CROSS_REFERENCES_VIEW_CLASS_KEY,
                    InstanceProvider(EventCrossReferencesView),
                    scope=singleton)
        binder.bind(guiinjectorkeys.DOCUMENT_FILE_REFERENCES_VIEW_CLASS_KEY,
                    InstanceProvider(DocumentFileReferencesView),
                    scope=singleton)
        binder.bind(guiinjectorkeys.DOCUMENT_EVENT_REFERENCES_VIEW_CLASS_KEY,
                    InstanceProvider(DocumentEventReferencesView),
                    scope=singleton)
        binder.bind(guiinjectorkeys.EVENT_DOCUMENT_REFERENCES_VIEW_CLASS_KEY,
                    InstanceProvider(EventDocumentReferencesView),
                    scope=singleton)
        binder.bind(guiinjectorkeys.EVENT_TYPE_REFERENCES_VIEW_CLASS_KEY,
                    InstanceProvider(EventTypeReferencesView),
                    scope=singleton)
Exemplo n.º 4
0
 def get(self, key, provider):
     if self.context is None:
         raise UnsatisfiedRequirement(None, key)
     try:
         return self.context[key]
     except KeyError:
         provider = InstanceProvider(provider.get(self.injector))
         self.context[key] = provider
         return provider
Exemplo n.º 5
0
 def get(self, key, provider):
     if self.context is None:
         raise UnsatisfiedRequirement(None, key)
     try:
         return self.context[key]
     except KeyError:
         provider = InstanceProvider(provider.get())
         self.context[key] = provider
         return provider
Exemplo n.º 6
0
 def configure(self, binder):
     binder.bind('ansible_client', to=AnsibleClient)
     binder.bind('args', to=InstanceProvider(self._args), scope=singleton)
     binder.bind('emr_cluster', to=EmrCluster)
     binder.bind('emr_deploy', to=EmrDeploy)
     binder.bind('excel_writer', to=ExcelWriter, scope=singleton)
     binder.bind('filesystem', to=Filesystem, scope=singleton)
     binder.bind('hdfs', to=HDFSFilesystem)
     binder.bind('hive_templates_render', to=HiveTemplatesRender)
     binder.bind('interactive_cluster_id', to=ClusterId, scope=singleton)
     binder.bind('interactive_configuration_file',
                 to=ConfigurationFile,
                 scope=singleton)
     binder.bind('interactive_default_configuration',
                 to=DefaultConfiguration)
     binder.bind('interactive_properties_file', to=PropertiesFile)
     binder.bind('job_flow', to=RunJobFlow)
     binder.bind('job_flow_configuration', to=JobFlowConfigurationParser)
     binder.bind('object_configuration',
                 to=WfConfigurationObject,
                 scope=singleton)
     binder.bind('templates_lib', to=TemplatesLib)
     binder.bind('wf_configuration', to=WorkflowConfiguration)
     binder.bind('wf_templates_render', to=WfTemplatesRender)
     binder.bind('yaml_configuration', to=YamlConfiguration)
     binder.bind('yaml_configuration_writer',
                 to=WorkflowsYamlConfigurationWriter)
Exemplo n.º 7
0
 def _get_or_set_provider(self, context_var, provider) -> InstanceProvider:
     try:
         value = context_var.get()
     except LookupError:
         value = InstanceProvider(provider.get(self.injector))
         context_var.set(value)
     return value
Exemplo n.º 8
0
    def get_polygon(self, arg_string):
        """Get class using reflection and Dependency Injection with API Injector"""

        self.parser.set_string(arg_string)
        arguments = self.parser.argument_parser().get_arguments()

        # instead of abstract fabric have used reflection and assential injection
        TypePolygon = getattr(importlib.import_module("models.type_polygons"),
                              arguments[0])
        InjectedPolygon = BoundKey(TypePolygon,
                                   x=InstanceProvider(arguments[1]),
                                   y=InstanceProvider(arguments[2]),
                                   side=InstanceProvider(arguments[3]),
                                   n=InstanceProvider(arguments[4]))

        injector = Injector()
        polygon = injector.get(InjectedPolygon)

        self.notify_observer(polygon)
        return polygon
    def configure(self, binder):

        binder.bind(guiinjectorkeys.WINDOW_MANAGER_KEY,
                    ClassProvider(WindowManager),
                    scope=singleton)

        binder.bind(guiinjectorkeys.EVENT_WINDOW_KEY,
                    ClassProvider(EventWindow),
                    scope=singleton)
        binder.bind(guiinjectorkeys.DOCUMENT_WINDOW_KEY,
                    ClassProvider(DocumentWindow),
                    scope=singleton)

        binder.bind(guiinjectorkeys.EVENT_MENU_ADDITIONS_KEY,
                    InstanceProvider([]))
        binder.bind(guiinjectorkeys.DOCUMENT_MENU_ADDITIONS_KEY,
                    InstanceProvider([]))

        binder.bind(guiinjectorkeys.DOCUMENT_WINDOW_ADDITIONAL_REFERENCES_KEY,
                    InstanceProvider([]))
        binder.bind(guiinjectorkeys.EVENT_WINDOW_ADDITIONAL_REFERENCES_KEY,
                    InstanceProvider([]))
Exemplo n.º 10
0
    def configure(self, binder):

        super().configure(binder)

        binder.bind(SYSTEMATIC_POINT_SELECTION_DIALOG_KEY,
                    ClassProvider(SystematicPointSelectionDialog),
                    scope=singleton)
        binder.bind(SYSTEMATIC_POINT_SELECTION_PRESENTER_KEY,
                    ClassProvider(SystematicPointSelectionPresenter),
                    scope=singleton)

        binder.bind(DOCUMENT_SYSTEMATIC_REFERENCES_PRESENTER_KEY,
                    ClassProvider(DocumentSystematicReferencesPresenter),
                    scope=singleton)
        binder.bind(DOCUMENT_SYSTEMATIC_REFERENCES_VIEW_CLASS_KEY,
                    InstanceProvider(DocumentSystematicReferenceView),
                    scope=singleton)

        binder.bind(SYSTEMATIC_MENU_ADDITIONS_PRESENTER_KEY,
                    ClassProvider(SystematicMenuAdditionsPresenter),
                    scope=singleton)
        binder.bind(guiinjectorkeys.DOCUMENT_FILTER_DIALOG_KEY,
                    ClassProvider(SystematicDocumentFilterDialog),
                    scope=singleton)
Exemplo n.º 11
0
def test_binder_provider_for_method_with_explicit_provider():
    injector = Injector()
    binder = injector.binder
    provider = binder.provider_for(int, to=InstanceProvider(1))
    assert type(provider) is InstanceProvider
    assert provider.get(injector) == 1
Exemplo n.º 12
0
 def configure(binder):
     binder.bind(InjectMe, to=InstanceProvider(InjectMe()))
Exemplo n.º 13
0
 def configure(binder):
     binder.bind(ProviderOf[int], to=InstanceProvider(None))
Exemplo n.º 14
0
def test_binder_provider_for_method_with_explicit_provider():
    binder = Injector().binder
    provider = binder.provider_for(int, to=InstanceProvider(1))
    assert (type(provider) is InstanceProvider)
    assert (provider.get() == 1)
Exemplo n.º 15
0
interface_bindings = {
    "web_container": {
        "to": ClassProvider(web_container.WebContainer),
        "scope": singleton
    },
    "ioloop": {
        "to": IOLoopInstanceProvider(),
        "scope": singleton
    },
    "http_server": {
        "to": HTTPServerInstanceProvider(),
        "scope": singleton
    },
    "configuration": {
        "to": InstanceProvider(settings.read_configuration()),
        "scope": singleton
    },
    "msg_broker_client": {
        "to": ClassProvider(pika_client.PikaClientForTornado),
        "scope": singleton
    },
    "instant_messenger": {
        "to": ClassProvider(instant_message_websockets.InstantMessenger),
        "scope": noscope
    },
    "im_incoming_queue": {
        "to": ClassProvider(pika_client.ImIncomingQueue),
        "scope": noscope
    },
    "im_message_publisher": {
Exemplo n.º 16
0
from injector import InstanceProvider
from injector import singleton


class MockObject(object):
    pass

mock_object = MockObject()

interface_bindings = {
    "mock_object": {"to": InstanceProvider(mock_object), "scope": singleton},
}