diff --git a/aries_cloudagent/core/profile.py b/aries_cloudagent/core/profile.py index 7b2b2f50da..2c0642a4e9 100644 --- a/aries_cloudagent/core/profile.py +++ b/aries_cloudagent/core/profile.py @@ -1,8 +1,9 @@ """Classes for managing profile information within a request context.""" -import logging from abc import ABC, abstractmethod +import logging from typing import Any, Mapping, Optional, Type +from weakref import ref from ..config.base import InjectionError from ..config.injection_context import InjectionContext @@ -30,10 +31,16 @@ def __init__( created: bool = False, ): """Initialize a base profile.""" - self._context = context or InjectionContext() self._created = created self._name = name or Profile.DEFAULT_NAME + context = context or InjectionContext() + scope = "profile:" + self._name + if sub := context.settings.get("wallet.id"): + scope += ":" + sub + self._context = context.start_scope(scope) + self._context.injector.bind_instance(Profile, ref(self)) + @property def backend(self) -> str: """Accessor for the backend implementation name.""" @@ -163,6 +170,8 @@ def __init__( self._profile = profile self._events = [] + self._context.injector.bind_instance(ProfileSession, ref(self)) + async def _setup(self): """Create the underlying session or transaction."""