How to use the punq.__init__.Scope function in punq

To help you get started, we’ve selected a few punq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bobthemighty / punq / punq / __init__.py View on Github external
def register(
        self, service, factory=empty, instance=empty, scope=Scope.transient, **kwargs
    ):
        resolve_args = kwargs or {}

        if instance is not empty:
            self.register_service_and_instance(service, instance)
        elif factory is empty:
            self.register_concrete_service(service, scope)
        elif callable(factory):
            self.register_service_and_impl(service, scope, factory, resolve_args)
        else:
            raise InvalidRegistrationException(
                f"Expected a callable factory for the service {service} but received {factory}"
            )

        self._update_localns(service)
        ensure_forward_ref(self, service, factory, instance, **kwargs)