Skip to content

Commit 58002da

Browse files
committed
refactor: 更改 GetOrCreate 签名
1 parent 7826f22 commit 58002da

File tree

3 files changed

+9
-39
lines changed

3 files changed

+9
-39
lines changed

src/BootstrapBlazor/Extensions/ITcpSocketFactoryExtensions.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/BootstrapBlazor/Services/TcpSocket/DefaultTcpSocketFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ class DefaultTcpSocketFactory(IServiceProvider provider) : ITcpSocketFactory
1616
{
1717
private readonly ConcurrentDictionary<string, ITcpSocketClient> _pool = new();
1818

19-
public ITcpSocketClient GetOrCreate(string name, IPEndPoint endPoint)
19+
public ITcpSocketClient GetOrCreate(string name, Func<string, IPEndPoint> valueFactory)
2020
{
2121
return _pool.GetOrAdd(name, key =>
2222
{
23+
var endPoint = valueFactory(key);
2324
var client = new DefaultTcpSocketClient(endPoint)
2425
{
2526
Logger = provider.GetService<ILogger<DefaultTcpSocketClient>>()

src/BootstrapBlazor/Services/TcpSocket/ITcpSocketFactory.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ namespace BootstrapBlazor.Components;
1313
public interface ITcpSocketFactory : IDisposable
1414
{
1515
/// <summary>
16-
/// Retrieves an existing TCP socket client by name or creates a new one if it does not exist.
16+
/// Retrieves an existing TCP socket client by name or creates a new one using the specified factory function.
1717
/// </summary>
18-
/// <param name="name">The unique name used to identify the TCP socket client. Cannot be null or empty.</param>
19-
/// <param name="endPoint">The network endpoint to associate with the TCP socket client. Must be a valid <see
20-
/// cref="System.Net.IPEndPoint"/> instance.</param>
21-
/// <returns>An instance of <see cref="ITcpSocketClient"/> representing the TCP socket client associated with the specified
22-
/// name and endpoint. If a client with the given name already exists, the existing instance is returned; otherwise,
23-
/// a new client is created.</returns>
24-
ITcpSocketClient GetOrCreate(string name, IPEndPoint endPoint);
18+
/// <param name="name">The unique name identifying the TCP socket client. Cannot be null or empty.</param>
19+
/// <param name="valueFactory">A factory function that generates an <see cref="IPEndPoint"/> for the client. The function is invoked if a
20+
/// client with the specified name does not already exist.</param>
21+
/// <returns>An instance of <see cref="ITcpSocketClient"/> associated with the specified name. If a client with the given
22+
/// name already exists, the existing instance is returned; otherwise, a new instance is created.</returns>
23+
ITcpSocketClient GetOrCreate(string name, Func<string, IPEndPoint> valueFactory);
2524

2625
/// <summary>
2726
/// Removes the TCP socket client associated with the specified name.

0 commit comments

Comments
 (0)