-
-
Notifications
You must be signed in to change notification settings - Fork 363
feat(ISocketClientProvider): add ISocketClientProvider service #6329
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
Reviewer's GuideOverhauls the TCP socket client to adopt a provider-based design (ISocketClientProvider) with dependency injection, consolidating configuration in SocketClientOptions and updating factories, interfaces, and unit tests to align with the new model. ER diagram for changes to TCP socket client data typeserDiagram
ITcpSocketClient ||--o{ TcpSocketClientBase : implements
TcpSocketClientBase ||--o{ DefaultTcpSocketClient : extends
ISocketClientProvider ||--o{ DefaultSocketClientProvider : implements
TcpSocketClientBase }o--|| ISocketClientProvider : uses
TcpSocketClientBase }o--|| SocketClientOptions : has
ISocketClientProvider {
bool IsConnected
IPEndPoint LocalEndPoint
}
SocketClientOptions {
int ReceiveBufferSize
bool IsAutoReceive
int ConnectTimeout
int SendTimeout
int ReceiveTimeout
IPEndPoint LocalEndPoint
}
Class diagram for the new ISocketClientProvider-based TCP socket client architectureclassDiagram
class ITcpSocketClient {
+bool IsConnected
+SocketClientOptions Options
+IPEndPoint LocalEndPoint
+Func<ReadOnlyMemory<byte>, ValueTask> ReceivedCallBack
+ValueTask<bool> ConnectAsync(IPEndPoint, CancellationToken)
+ValueTask<bool> SendAsync(ReadOnlyMemory<byte>, CancellationToken)
+ValueTask<Memory<byte>> ReceiveAsync(CancellationToken)
+ValueTask DisposeAsync()
}
class TcpSocketClientBase {
#ISocketClientProvider? SocketClientProvider
#ILogger? Logger
+IServiceProvider? ServiceProvider
+SocketClientOptions Options
+bool IsConnected
+IPEndPoint LocalEndPoint
+Func<ReadOnlyMemory<byte>, ValueTask>? ReceivedCallBack
+ValueTask<bool> ConnectAsync(IPEndPoint, CancellationToken)
+ValueTask<bool> SendAsync(ReadOnlyMemory<byte>, CancellationToken)
+ValueTask<Memory<byte>> ReceiveAsync(CancellationToken)
+ValueTask DisposeAsync()
}
class DefaultTcpSocketClient {
}
class ISocketClientProvider {
+bool IsConnected
+IPEndPoint LocalEndPoint
+ValueTask ConnectAsync(IPEndPoint, CancellationToken)
+ValueTask<bool> SendAsync(ReadOnlyMemory<byte>, CancellationToken)
+ValueTask<int> ReceiveAsync(Memory<byte>, CancellationToken)
+ValueTask CloseAsync()
}
class DefaultSocketClientProvider {
}
ITcpSocketClient <|.. TcpSocketClientBase
TcpSocketClientBase <|-- DefaultTcpSocketClient
ISocketClientProvider <|.. DefaultSocketClientProvider
TcpSocketClientBase --> ISocketClientProvider : uses
DefaultTcpSocketClient --> TcpSocketClientBase
DefaultSocketClientProvider ..|> ISocketClientProvider
Class diagram for SocketClientOptions and its usageclassDiagram
class SocketClientOptions {
+int ReceiveBufferSize
+bool IsAutoReceive
+int ConnectTimeout
+int SendTimeout
+int ReceiveTimeout
+IPEndPoint LocalEndPoint
}
TcpSocketClientBase --> SocketClientOptions : has
DefaultTcpSocketClient --> SocketClientOptions : has
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @ArgoZhang - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Services/TcpSocket/TcpSocketClientBase.cs:42` </location>
<code_context>
+ /// Gets or sets the service provider used to resolve dependencies.
/// </summary>
- public int ReceiveBufferSize { get; set; } = 1024 * 64;
+ [NotNull]
+ public IServiceProvider? ServiceProvider { get; set; }
/// <summary>
</code_context>
<issue_to_address>
The [NotNull] attribute on a public settable property may not provide the intended guarantees.
Consider enforcing non-null assignment through constructor injection or property validation, as [NotNull] does not guarantee non-null values for public settable properties.
Suggested implementation:
```csharp
/// Gets the service provider used to resolve dependencies.
/// </summary>
```
```csharp
public IServiceProvider ServiceProvider { get; }
```
You will need to:
1. Add a constructor to the class that takes an `IServiceProvider` parameter and assigns it to the `ServiceProvider` property.
2. Update all usages and instantiations of this class to provide a non-null `IServiceProvider` via the constructor.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6329 +/- ##
========================================
Coverage 99.99% 100.00%
========================================
Files 717 717
Lines 31568 31557 -11
Branches 4455 4457 +2
========================================
- Hits 31567 31557 -10
+ Partials 1 0 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6328
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Introduce an ISocketClientProvider abstraction and refactor the TCP socket client implementation to use provider-based dependency injection and centralized SocketClientOptions configuration.
New Features:
Enhancements:
Tests: