Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
>>> class EmailSender:
... def send(self, msg):
... pass
...
>>> class SmtpEmailSender(EmailSender):
... def send(self, msg):
... print("Sending message via smtp: " + msg)
...
>>> container.register(EmailSender, SmtpEmailSender)
>>> instance = container.resolve(EmailSender)
>>> instance.send("Hello")
Sending message via smtp: Hello
"""
self.__registrations[service].append(
Registration(
service, scope, impl, self._get_needs_for_ctor(impl), resolve_args
)
>>> container = Container()
>>> class FileReader:
... def read(self):
... # Assorted legerdemain and rigmarole
... pass
...
>>> container.register(FileReader)
"""
if not inspect.isclass(service):
raise InvalidRegistrationException(
"The service %s can't be registered as its own implementation"
% (repr(service))
)
self.__registrations[service].append(
Registration(service, scope, service, self._get_needs_for_ctor(service), {})
)