Common: Accept Union[str, Type[AbstractEvent]] in EventSerializerRegistry

This commit is contained in:
Ilija Lazoroski 2022-08-18 09:42:05 +02:00
parent 23604009a0
commit a32d9359b0
1 changed files with 10 additions and 6 deletions

View File

@ -1,17 +1,21 @@
from typing import Type, Union
from common.event_serializers import IEventSerializer
from common.events import AbstractEvent
class EventSerializerRegistry:
"""
Registry for event serializers
Registry for event serializers using event class.
"""
def __init__(self):
self._registry = {}
def __setitem__(self, event_class_name: str, event_serializer: IEventSerializer):
self._registry[event_class_name] = event_serializer
def __setitem__(
self, event_class: Union[str, Type[AbstractEvent]], event_serializer: IEventSerializer
):
self._registry[event_class] = event_serializer
def __getitem__(self, event_class_name: str):
event_serializer = self._registry[event_class_name]
return event_serializer
def __getitem__(self, event_class: Union[str, Type[AbstractEvent]]):
return self._registry[event_class]