Skip to content

Commit 5ee4bfe

Browse files
committed
fix: connectionFactory 제거
과한 설계 connectionFactory 제거
1 parent fb7110d commit 5ee4bfe

File tree

8 files changed

+15
-142
lines changed

8 files changed

+15
-142
lines changed

ProjectVG.Api/Middleware/WebSocketMiddleware.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Net.WebSockets;
33
using ProjectVG.Application.Services.WebSocket;
44
using ProjectVG.Application.Services.Session;
5-
using ProjectVG.Common.Models.Session;
5+
using ProjectVG.Infrastructure.Realtime.WebSocketConnection;
66

77
namespace ProjectVG.Api.Middleware
88
{
@@ -12,20 +12,16 @@ public class WebSocketMiddleware
1212
private readonly ILogger<WebSocketMiddleware> _logger;
1313
private readonly IWebSocketManager _webSocketService;
1414
private readonly IConnectionRegistry _connectionRegistry;
15-
private readonly IClientConnectionFactory _connectionFactory;
16-
1715
public WebSocketMiddleware(
1816
RequestDelegate next,
1917
ILogger<WebSocketMiddleware> logger,
2018
IWebSocketManager webSocketService,
21-
IConnectionRegistry connectionRegistry,
22-
IClientConnectionFactory connectionFactory)
19+
IConnectionRegistry connectionRegistry)
2320
{
2421
_next = next;
2522
_logger = logger;
2623
_webSocketService = webSocketService;
2724
_connectionRegistry = connectionRegistry;
28-
_connectionFactory = connectionFactory;
2925
}
3026

3127
public async Task InvokeAsync(HttpContext context)
@@ -51,7 +47,7 @@ public async Task InvokeAsync(HttpContext context)
5147
}
5248

5349
// 3. 연결 생성 및 등록
54-
var connection = _connectionFactory.Create(actualSessionId, socket, userId: null);
50+
var connection = new WebSocketClientConnection(actualSessionId, socket, userId: null);
5551
_connectionRegistry.Register(actualSessionId, connection);
5652

5753
// 4. 세션 생성 (이제 연결이 등록된 상태)

ProjectVG.Application/Services/Character/CharacterService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public async Task<IEnumerable<CharacterDto>> GetAllCharactersAsync()
2525
return characterDtos;
2626
}
2727

28-
public async Task<CharacterDto?> GetCharacterByIdAsync(Guid id)
28+
public async Task<CharacterDto> GetCharacterByIdAsync(Guid id)
2929
{
3030
var character = await _characterRepository.GetByIdAsync(id);
3131
if (character == null) {
32-
return null;
32+
throw new NotFoundException(ErrorCode.CHARACTER_NOT_FOUND, id);
3333
}
3434

3535
var characterDto = new CharacterDto(character);

ProjectVG.Application/Services/Character/ICharacterService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface ICharacterService
1515
/// </summary>
1616
/// <param name="id">캐릭터 ID</param>
1717
/// <returns>캐릭터 정보</returns>
18-
Task<CharacterDto?> GetCharacterByIdAsync(Guid id);
18+
Task<CharacterDto> GetCharacterByIdAsync(Guid id);
1919

2020
/// <summary>
2121
/// 새 캐릭터를 생성합니다

ProjectVG.Application/Services/Character/TestCharacterService.cs

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

ProjectVG.Common/Models/Session/IClientConnectionFactory.cs

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

ProjectVG.Infrastructure/InfrastructureServiceCollectionExtensions.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
using ProjectVG.Infrastructure.Persistence.Repositories.Conversation;
1010
using ProjectVG.Infrastructure.Persistence.Repositories.Users;
1111
using ProjectVG.Infrastructure.Persistence.Session;
12-
using ProjectVG.Infrastructure.Realtime.WebSocketConnection;
13-
using ProjectVG.Common.Models.Session;
12+
1413

1514
using Microsoft.EntityFrameworkCore;
1615

@@ -26,7 +25,6 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti
2625
AddDatabaseServices(services, configuration);
2726
AddExternalApiClients(services, configuration);
2827
AddPersistenceServices(services);
29-
AddRealtimeServices(services);
3028

3129
return services;
3230
}
@@ -92,13 +90,5 @@ private static void AddPersistenceServices(IServiceCollection services)
9290
services.AddScoped<IUserRepository, SqlServerUserRepository>();
9391
services.AddSingleton<ISessionStorage, InMemorySessionStorage>();
9492
}
95-
96-
/// <summary>
97-
/// 실시간 통신 서비스
98-
/// </summary>
99-
private static void AddRealtimeServices(IServiceCollection services)
100-
{
101-
services.AddSingleton<IClientConnectionFactory, WebSocketClientConnectionFactory>();
102-
}
10393
}
10494
}

ProjectVG.Infrastructure/Realtime/WebSocketConnection/WebSocketClientConnection.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ public class WebSocketClientConnection : IClientConnection
1313
public DateTime ConnectedAt { get; set; } = DateTime.UtcNow;
1414
public System.Net.WebSockets.WebSocket WebSocket { get; set; } = null!;
1515

16+
public WebSocketClientConnection(string sessionId, System.Net.WebSockets.WebSocket socket, string? userId = null)
17+
{
18+
SessionId = sessionId;
19+
WebSocket = socket;
20+
UserId = userId;
21+
ConnectedAt = DateTime.UtcNow;
22+
}
23+
1624
/// <summary>
1725
/// 텍스트 메시지를 전송합니다
1826
/// </summary>

ProjectVG.Infrastructure/Realtime/WebSocketConnection/WebSocketClientConnectionFactory.cs

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

0 commit comments

Comments
 (0)