From: "Lukas Wagner" <l.wagner@proxmox.com>
To: "Robert Obkircher" <r.obkircher@proxmox.com>,
<pdm-devel@lists.proxmox.com>
Subject: Re: [RFC datacenter-manager/proxmox 0/7] inject application context via rpcenv for easier integration testing
Date: Wed, 04 Feb 2026 13:23:55 +0100 [thread overview]
Message-ID: <DG66B16FHQHH.2MPGXZGAU20RX@proxmox.com> (raw)
In-Reply-To: <f760f217-41a5-4773-99b2-fe2f1967e193@proxmox.com>
On Tue Feb 3, 2026 at 12:02 PM CET, Robert Obkircher wrote:
> On 1/29/26 14:43, Lukas Wagner wrote:
>> What I'm not so sure about yet and where I have not done any experiments is the
>> case where the entire API handler is defined in a shared crate. These of course
>> cannot access the product-specific struct. Many of these rely on some form of
>> static initialization, either directly or indirectly (e.g.
>> proxmox-product-config).
>>
>> I'd be happy about any ideas for these cases.
>
> I'm not very familiar with any of this, but have you considered making
> dependency injection more flexible?
>
> If API handlers can choose what they want (e.g. with a InjectedRef<T>
> parameters) they never need to know about an application specific type
> like PdmApplication.
>
> Tests would then also now exactly which dependencies to construct and
> they could just pass them by reference.
>
> As far as I can tell, Actix [1] also seems to support multiple types
> for app_data and Axum has a slightly different approach with the
> FromRef trait used for substates [2].
>
> [1]
> https://docs.rs/actix-web/latest/actix_web/struct.Scope.html#method.app_data
> [2] https://docs.rs/axum/latest/axum/extract/struct.State.html#substates
>
Hi Robert,
thank you a lot for your input.
This is indeed an interesting idea.
I've checked out how this is implemented in actix-web, internally these
state objects basically boil down to a map of TypeId -> Box<dyn Any>.
The 'extractors' in the function signatures are nice, I'm wondering if
something like this could be integrated retroactively without
introducing huge breaking changes into our API server stack.
If not, we still could have such a map somewhere in rpcenv and then have
something like
let xyz_context = extract_context::<XyzContext>(&rpcenv)?;
which then does the lookup in the map and perform the cast from Any.
The context type would then be defined by the shared crate,
instantiated by the application and injected during server startup,
similar to how I handled the PdmApplication struct in this RFC.
I'll do some experiments and send an updated RFC if something
interesting comes out.
Thanks a lot!
prev parent reply other threads:[~2026-02-04 12:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-29 13:44 Lukas Wagner
2026-01-29 13:44 ` [RFC proxmox 1/1] router: rpc environment: allow to provide a application-specific context handle via rpcenv Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 1/6] connection: store client factory in an Arc and add public getter Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 2/6] parallel fetcher: allow to use custom client factory Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 3/6] introduce PdmApplication struct and inject it during API server startup Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 4/6] remote updates: use PdmApplication object to derive paths, permissions and client factory Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 5/6] tests: add captured responses for integration tests Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 6/6] tests: add basic integration tests for the remote updates API Lukas Wagner
2026-02-03 11:02 ` [RFC datacenter-manager/proxmox 0/7] inject application context via rpcenv for easier integration testing Robert Obkircher
2026-02-04 12:23 ` Lukas Wagner [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DG66B16FHQHH.2MPGXZGAU20RX@proxmox.com \
--to=l.wagner@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
--cc=r.obkircher@proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.