Skip to content

Conversation

jaspecla
Copy link
Member

This pull request includes significant refactoring and improvements to the SimpleL7Proxy project. The changes focus on improving the handling of cancellation tokens, making services injectable, and transitioning some classes to use the IHostedService interface for better integration with the .NET Generic Host.

Transition to IHostedService:

  • ProxyWorkerCollection.cs: Converted ProxyWorkerCollection to extend BackgroundService for better integration with the hosting environment.
  • Server.cs: Converted Server to extend BackgroundService and added handling for application stopping events. [1] [2] [3] [4]

Interface and Class Adjustments:

  • IBackendService.cs: Updated the Start method signature to remove the CancellationToken parameter.
  • ProxyWorker.cs: Changed the Backends dependency to IBackendService to use the interface instead of the concrete class. [1] [2]
  • Removed the IServer interface as it is no longer needed.

Refactoring and Dependency Injection Improvements:

  • Backends.cs: Introduced CancellationTokenSource and CancellationToken for better task management and added IHostApplicationLifetime to handle application stopping events. [1] [2] [3] [4] [5] [6] [7] [8]
  • Program.cs: Updated the service registration to use IHostedService and removed direct handling of CancellationTokenSource. [1] [2] [3] [4]

These changes collectively improve the maintainability and testability of the codebase by leveraging dependency injection and the .NET Generic Host's capabilities.

Copy link
Collaborator

@petemessina petemessina left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 7 out of 18 changed files in this pull request and generated 1 comment.

Files not reviewed (11)
  • src/SimpleL7Proxy/SimpleL7Proxy.csproj: Language not supported
  • src/SimpleL7Proxy/IServer.cs: Evaluated as low risk
  • src/SimpleL7Proxy/IBackendService.cs: Evaluated as low risk
  • src/SimpleL7Proxy/BackendOptions.cs: Evaluated as low risk
  • src/SimpleL7Proxy/BackendHost.cs: Evaluated as low risk
  • src/SimpleL7Proxy/Program.cs: Evaluated as low risk
  • src/SimpleL7Proxy/Backend/IBackendService.cs: Evaluated as low risk
  • src/SimpleL7Proxy/Proxy/ProxyWorker.cs: Evaluated as low risk
  • src/SimpleL7Proxy/Proxy/ProxyWorkerCollection.cs: Evaluated as low risk
  • src/SimpleL7Proxy/Queue/BlockingPriorityQueue.cs: Evaluated as low risk
  • src/SimpleL7Proxy/server.cs: Evaluated as low risk
Comments suppressed due to low confidence (3)

src/SimpleL7Proxy/Backend/BackendHostConfig.cs:13

  • [nitpick] The Host property is modified in the constructor, which can be confusing. Consider making it read-only or using a different approach.
public string Host { get; private set; } = string.Empty;

src/SimpleL7Proxy/Backend/BackendHostHealth.cs:22

  • [nitpick] The variable name lockObj is ambiguous. It should be renamed to lockObject for clarity.
private readonly Lock lockObj = new();

src/SimpleL7Proxy/Backend/BackendHostHealthCollection.cs:15

  • The logger parameter should be explicitly typed as 'ILogger' for clarity.
public BackendHostHealthCollection(IOptions<BackendOptions> options, ILogger<BackendHostHealth> logger)


public class BackendHostHealthCollection : IBackendHostHealthCollection
{
public List<BackendHostHealth> Hosts { get; } = [];
Copy link
Preview

Copilot AI Jan 17, 2025

Choose a reason for hiding this comment

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

The Hosts property is initialized with an empty list using invalid C# syntax. It should be 'new List()'.

Suggested change
public List<BackendHostHealth> Hosts { get; } = [];
public List<BackendHostHealth> Hosts { get; } = new List<BackendHostHealth>();

Copilot uses AI. Check for mistakes.

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.

2 participants