Skip to content

Conversation

@danielmarbach
Copy link
Contributor

No description provided.

@danielmarbach danielmarbach force-pushed the expose-service-provider-playground branch from 8bd37c7 to e2998d4 Compare January 5, 2026 14:23
@danielmarbach danielmarbach changed the title Prototype DI access Improve service collection and dependency injection access Jan 5, 2026
@danielmarbach danielmarbach marked this pull request as ready for review January 5, 2026 14:23
/// Transport implementations can use this property to determine whether they can resolve dependencies from the service provider during initialization.
/// </remarks>
[MemberNotNullWhen(true, nameof(ServiceProvider))]
public bool SupportsDependencyInjection => ServiceProvider is not null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized now we have effectively more modes we are supporting and I decided to split the property. During hosted scenarios that transport supports DI because Core will take care of calling ConfigureServices and set the provider on the host settings. During raw modes you might still have a need to access DI and then you don't necessarily have to set the CoreSettings. You might only call ConfigureServices and provide the service provider.

One thing that I don't particularly like is that a transport might not use the services but still the SupportsDependencyInjection is set to true which is slightly awkward, but I guess there is really no clean way to express that without breaking a lot of things.


public override Task<TransportInfrastructure> Initialize(HostSettings hostSettings, ReceiveSettings[] receivers, string[] sendingAddresses, CancellationToken cancellationToken = default)
{
if (hostSettings.SupportsDependencyInjection)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need a test that verifies IsHosted?

Plus technically do we need a raw transport seam test too? If yes where would we put it?

@andreasohlund andreasohlund merged commit 0dc00c0 into expose-service-provider Jan 6, 2026
4 checks passed
@andreasohlund andreasohlund deleted the expose-service-provider-playground branch January 6, 2026 07:52
andreasohlund added a commit that referenced this pull request Jan 6, 2026
* Expose the service provider on the transport seam

* Move up and improve documentation

* Remove using

* Improve service collection and dependency injection access (#7571)

* Improve service collection and dependency injection access

* IsRawMode

---------

Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com>

* Remove no longer needed assert

---------

Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com>
Co-authored-by: Daniel Marbach <daniel.marbach@openplace.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants