Common: Add release_convention()

This commit is contained in:
Mike Salvatore 2022-06-16 09:12:09 -04:00
parent 8fb97fc8c0
commit c53864cdd7
3 changed files with 20 additions and 0 deletions

View File

@ -171,6 +171,16 @@ class DIContainer:
DIContainer._del_key(self._type_registry, interface) DIContainer._del_key(self._type_registry, interface)
DIContainer._del_key(self._instance_registry, interface) DIContainer._del_key(self._instance_registry, interface)
def release_convention(self, type_: Type[T], name: str):
"""
Deregister a convention
:param **type_**: The `type` (class) of the dependency
:param name: The name of the dependency parameter
"""
convention_identifier = (type_, name)
DIContainer._del_key(self._convention_registry, convention_identifier)
@staticmethod @staticmethod
def _del_key(mapping: MutableMapping[T, Any], key: T): def _del_key(mapping: MutableMapping[T, Any], key: T):
""" """

View File

@ -366,3 +366,12 @@ def test_register_convention__instance_properly_resolved(container):
assert id(service_a_instance) == id(test_9.service_a) assert id(service_a_instance) == id(test_9.service_a)
assert test_9.my_str == my_str assert test_9.my_str == my_str
def test_release_convention(container):
my_str = "test_string"
container.register_convention(str, "my_str", my_str)
with pytest.raises(ValueError):
container.release_convention(str, "my_str")
container.resolve(TestClass6)

View File

@ -182,6 +182,7 @@ GCPHandler # unused function (envs/monkey_zoo/blackbox/test_blackbox.py:57)
architecture # unused variable (monkey/infection_monkey/exploit/caching_agent_repository.py:25) architecture # unused variable (monkey/infection_monkey/exploit/caching_agent_repository.py:25)
response_code # unused variable (monkey/monkey_island/cc/services/aws/aws_command_runner.py:26) response_code # unused variable (monkey/monkey_island/cc/services/aws/aws_command_runner.py:26)
release_convention # unused method (monkey/common/di_container.py:174)
# TODO DELETE AFTER RESOURCE REFACTORING # TODO DELETE AFTER RESOURCE REFACTORING
NetworkMap NetworkMap