-
Notifications
You must be signed in to change notification settings - Fork 48
Better transport seam integration to enable dependency injection #4193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fbad0a5 to
5927123
Compare
bac749d to
aed1e60
Compare
aed1e60 to
00f29f3
Compare
…ers to leverage new DI capabilities
00f29f3 to
7a0ca15
Compare
johnsimons
left a comment
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
Line 34 in 1b522c5
| using PeriodicTimer timer = new(TimeSpan.FromDays(1), timeProvider); |
I am just wondering.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…ers to leverage new DI capabilities (#4193) Co-authored-by: danielmarbach <danielmarbach@users.noreply.github.com>
This PR is the outcome of a discussion related to changes done as part of #3965 which had to introduce a
ThroughputQueryProvidertype 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.