Let's say I have an AbstractFormatter class.
I register the base binding:
self.container.register(AbstractFormatter, JsonFormatter)
class Processor:
def __init__(
self,
json_formatter: AbstractFormatter,
):
self.json_formatter = json_formatter
But one specific class wants another implementation by the same contract:
class CustomProcessor:
def __init__(
self,
markdown_formatter: AbstractFormatter,
):
self.markdown_formatter = markdown_formatter
Now, I want to do the following:
(self.container.when(CustomProcessor)
.wants(AbstractFormatter)
.give(MarkdownFormatter))
I.e. only CustomProcessor should receive the markdown formatter.
P.S. Maybe there are other ways to do the same? Inspired by this.
Let's say I have an
AbstractFormatterclass.I register the base binding:
But one specific class wants another implementation by the same contract:
Now, I want to do the following:
I.e. only
CustomProcessorshould receive the markdown formatter.P.S. Maybe there are other ways to do the same? Inspired by this.