Skip to content

Conversation

@danielmarbach
Copy link
Contributor

@danielmarbach danielmarbach commented May 23, 2024

This PR is the outcome of a discussion related to changes done as part of #3965 which had to introduce a ThroughputQueryProvider type on the transport customization. By aligning the transport customization integration well enough with how the persistence seam integrates into the DI container it becomes possible to register types directly that then the transport infrastructure can resolve. This is demonstrated by migrating the queue length query providers to actual hosted services.

@danielmarbach danielmarbach force-pushed the transport-seam-di branch 4 times, most recently from fbad0a5 to 5927123 Compare June 5, 2024 04:36
@danielmarbach danielmarbach force-pushed the transport-seam-di branch 2 times, most recently from bac749d to aed1e60 Compare June 18, 2024 13:01
@danielmarbach danielmarbach changed the title TransportSeam DI Integrated the transport seam better into the host to be able to leverage DI (similar to the persistence seam) Jun 18, 2024
@danielmarbach danielmarbach marked this pull request as ready for review June 18, 2024 13:05
Copy link
Member

@johnsimons johnsimons left a comment

Choose a reason for hiding this comment

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

LGTM

using Microsoft.Extensions.Hosting;

public interface IProvideQueueLength
public interface IProvideQueueLength : IHostedService
Copy link
Member

Choose a reason for hiding this comment

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

I feel that the implementers need to decide whether using IHostedService is the right thing to do.
in other words, should this interface not implement IHostedService ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an excellent question. I was going down that path because the existing code and test was starting and stopping things to make it work. By not adding the hosted service interface the test code would become slightly more complex because it would have to retrieve the AbstractQueueLengthProvider and then start that. This would also mean we then technically need three registrations of which one would only ever be used by the transport tests. We can't just retrieve the IHostedService instance because while there is currently only one, there might be more later. So I'm kind of torn. I'll merge the PR and think about this a bit more.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I can see the complexity.
TBH, given this is not a public API, I am fine with it 😄

stop = new CancellationTokenSource();

poller = Task.Run(async () =>
while (!stoppingToken.IsCancellationRequested)
Copy link
Member

Choose a reason for hiding this comment

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

Would the PeriodicTimer be a better fit for this background task?
I used it in

using PeriodicTimer timer = new(TimeSpan.FromDays(1), timeProvider);
and feels nicer.
I am just wondering.

Copy link
Member

Choose a reason for hiding this comment

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

And yes, I noticed this is existing code and they are all the same pattern!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah the reason I use the while with the delay pattern is because the existing code was already doing that. At least from that perspective I wanted to stay compatible. I was aware the period timer pattern exists. It is also documented here https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-8.0&tabs=visual-studio#asynchronous-timed-background-task

Can you elaborate on the "feels nicer" part?

Copy link
Member

Choose a reason for hiding this comment

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

Can you elaborate on the "feels nicer" part?

There's not much to elaborate on; I guess, it feels shorter and more to the point.
But this is just my opinion, nothing wrong with the other approach either.

@danielmarbach danielmarbach merged commit 9fe20c9 into master Jun 19, 2024
@danielmarbach danielmarbach deleted the transport-seam-di branch June 19, 2024 07:03
@jpalac jpalac added this to the 5.3.0 milestone Jun 21, 2024
bording pushed a commit that referenced this pull request Jun 27, 2024
…ers to leverage new DI capabilities (#4193)

Co-authored-by: danielmarbach <danielmarbach@users.noreply.github.com>
@DavidBoike DavidBoike changed the title Integrated the transport seam better into the host to be able to leverage DI (similar to the persistence seam) Better transport seam integration to enable dependency injection Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants