aries-cloudagent-python icon indicating copy to clipboard operation
aries-cloudagent-python copied to clipboard

feat: inject profile and session

Open dbluhm opened this issue 1 year ago • 5 comments

This is yet another attempt at #2705 which was reverted in #2789 because of issues reported in #2777. This time, I have explicitly tested using the integration tests in the Multitenant provider plugin to ensure the same issue does not arise.

The same benefits mentioned in #2705 of course apply here. This makes it easier to provide pluggable components that depend on a Profile without the interface of those components accepting a profile in every method.

The primary difference between this PR and #2705 is that this ensures a unique scope based on wallet id of multi-tenant subwallets.

I have also tacked on injecting the session. This enables binding dependencies that require a session from plugins and other components. For instance, the DIDComm v2 work in #2959 could use this to bind a provider for the SecretsAdapter needed to provide access to Askar to the pack and unpack methods.

dbluhm avatar May 29 '24 02:05 dbluhm

This should help with unit testing, too?

@jamshale I hadn't thought about that but this could be used to inject test/mock dependencies in unit tests. We had strategies to do this already though so I'm not sure it changes too much. If we took advantage of this in more places, mocking dependencies would be simpler but that would require transitioning more places to using the injected profile.

dbluhm avatar May 29 '24 15:05 dbluhm

I've still got issues with entering a scope that isn't unique in the integration tests... I will take a deeper look. I'm beginning to question the value of the named scopes. ContextVars, for instance, don't name the contexts and require them to be globally unique. I'll look into that angle.

dbluhm avatar May 29 '24 16:05 dbluhm

I removed named scopes entirely. They served no significant purpose in practice and they were causing all sorts of trouble.

dbluhm avatar May 29 '24 23:05 dbluhm

@jamshale Yeah, the tests implied that there was some perceived use to the named scopes at some point in the past but it looks like in practice they were just never really used.

You could "recall" a particular scope by name and retrieve values out of it. But this would only ever be possible from a parent scope and it's just not common practice to, for example, obtain the bound values of a session from the profile scope that spawned it. That would probably be a bad idea, in fact lol.

In practice, the lifetimes of the InjectionContexts and references to the contexts are, I think, appropriately narrow and naturally fall out of (lexical) scope at the right times. So we don't need to access the scopes by name since we're using the references to them as bound to a profile or session, etc.

dbluhm avatar May 30 '24 19:05 dbluhm

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

sonarqubecloud[bot] avatar May 31 '24 19:05 sonarqubecloud[bot]