Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add instance and init to backing store factory singleton #252

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions kiota_abstractions/store/backing_store_factory_singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class BackingStoreFactorySingleton:
"""
Ensures that there is only a single instance of a Backing Store Factory.
"""
__instance = None
__init_arg = None

def __new__(cls, *args, **kwargs):
"""
Expand All @@ -34,11 +36,19 @@ def __new__(cls, *args, **kwargs):
cls.__instance = super(BackingStoreFactorySingleton, cls).__new__(cls)
return cls.__instance

def __init__(self,
backing_store_factory: BackingStoreFactory = None) -> None:
if backing_store_factory is None:
backing_store_factory = self.__class__.__init_arg
self._backing_store_factory = backing_store_factory

@classmethod
def get_instance(cls):
"""
Returns the instance of the class.
"""
if cls.__instance is None:
cls.__instance = cls()
return cls.__instance

def __init__(self, backing_store_factory: BackingStoreFactory) -> None:
Expand Down
Loading