Skip to content

Commit

Permalink
Merge pull request hyperledger#2705 from dbluhm/feature/injected-profile
Browse files Browse the repository at this point in the history
feat: inject profile
  • Loading branch information
swcurran committed Jan 11, 2024
2 parents 1cfd492 + f3fd68c commit 2a18657
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion aries_cloudagent/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,5 @@ def copy(self) -> "BaseInjector":
class BaseProvider(ABC):
"""Base provider class."""

def provide(self, settings: BaseSettings, injector: BaseInjector):
def provide(self, settings: BaseSettings, injector: BaseInjector) -> Any:
"""Provide the object instance given a config and injector."""
10 changes: 6 additions & 4 deletions aries_cloudagent/config/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import hashlib

from typing import Sequence, Union
from typing import Optional, Sequence, Union
from weakref import ReferenceType

from ..utils.classloader import DeferLoad
Expand Down Expand Up @@ -44,16 +44,18 @@ def __init__(
self,
instance_cls: Union[str, type],
*ctor_args,
init_method: str = None,
init_method: Optional[str] = None,
**ctor_kwargs
):
"""Initialize the class provider."""
self._ctor_args = ctor_args
self._ctor_kwargs = ctor_kwargs
self._init_method = init_method
if isinstance(instance_cls, str):
instance_cls = DeferLoad(instance_cls)
self._instance_cls = instance_cls
cls = DeferLoad(instance_cls)
else:
cls = instance_cls
self._instance_cls: Union[type, DeferLoad] = cls

def provide(self, config: BaseSettings, injector: BaseInjector):
"""Provide the object instance given a config and injector."""
Expand Down
12 changes: 9 additions & 3 deletions aries_cloudagent/core/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from abc import ABC, abstractmethod
from typing import Any, Mapping, Optional, Type
from weakref import ref

from .event_bus import EventBus, Event
from ..config.base import InjectionError
Expand All @@ -27,14 +28,19 @@ class Profile(ABC):
def __init__(
self,
*,
context: InjectionContext = None,
name: str = None,
context: Optional[InjectionContext] = None,
name: Optional[str] = None,
created: bool = False,
):
"""Initialize a base profile."""
self._context = context or InjectionContext()
context = context or InjectionContext()
scope = "profile"
if name:
scope += ":" + name
self._context = context.start_scope(scope)
self._created = created
self._name = name or Profile.DEFAULT_NAME
self._context.injector.bind_instance(Profile, ref(self))

@property
def backend(self) -> str:
Expand Down

0 comments on commit 2a18657

Please sign in to comment.