-
Notifications
You must be signed in to change notification settings - Fork 1k
.NET Purview Middleware: Improve Background Job Runner Injection #3256
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
.NET Purview Middleware: Improve Background Job Runner Injection #3256
Conversation
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.
Pull request overview
This PR fixes a dependency injection issue where BackgroundJobRunner was not being instantiated in certain circumstances, preventing background jobs from running. The fix makes PurviewWrapper directly depend on IBackgroundJobRunner instead of IChannelHandler, ensuring the background workers are always created.
Changes:
- Created new
IBackgroundJobRunnerinterface with aShutdownAsyncmethod - Changed
PurviewWrapperto depend onIBackgroundJobRunnerinstead ofIChannelHandler - Moved channel shutdown logic from
IChannelHandlerintoIBackgroundJobRunner.ShutdownAsync - Updated unit tests to use
IBackgroundJobRunnermock
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Purview/IBackgroundJobRunner.cs | New interface for background job management with ShutdownAsync method |
| dotnet/src/Microsoft.Agents.AI.Purview/BackgroundJobRunner.cs | Implements IBackgroundJobRunner and adds ShutdownAsync method that delegates to IChannelHandler |
| dotnet/src/Microsoft.Agents.AI.Purview/PurviewWrapper.cs | Updates dependency from IChannelHandler to IBackgroundJobRunner and calls ShutdownAsync on dispose |
| dotnet/src/Microsoft.Agents.AI.Purview/PurviewExtensions.cs | Registers BackgroundJobRunner as IBackgroundJobRunner in DI container |
| dotnet/tests/Microsoft.Agents.AI.Purview.UnitTests/PurviewWrapperTests.cs | Updates test mocks to use IBackgroundJobRunner instead of IChannelHandler |
…rosoft#3256) * Clean up background job dependency injection * Fix xml documentation grammar
Motivation and Context
The PurviewWrapper class does not directly depend on BackgroundJobRunner. This causes dependency injection to not instantiate BackgroundJobRunner in certain circumstances. Since BackgroundJobRunner creates the workers which process background jobs, this prevents jobs from running in the background. This change adds BackgroundJobRunner as a dependency of PurviewWrapper to ensure background workers are always created when the PurviewWrapper is created.
Description
This change is relatively small. It swaps the IChannelHandler dependency for IBackgroundJobRunner and moves the channel shutdown code from IChannelHandler into IBackgroundJobRunner.
Contribution Checklist