Skip to content

Commit

Permalink
fix: scoped dbContext
Browse files Browse the repository at this point in the history
  • Loading branch information
mtai0524 committed Nov 22, 2024
1 parent 3c9a1d3 commit 2c78d14
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion NotaionWebApp/Notaion.Application/Services/ChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task<int> HideChatAllAsync()
*/
public async Task<List<ChatResponseDto>> GetChatsAsync()
{
var chats = await _unitOfWork.ChatRepository.GetAllAsync();
var chats = await _unitOfWork.ChatRepository.GetAsync(x => x.Hide == false);
return _mapper.Map<List<ChatResponseDto>>(chats);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi
{
options.UseSqlServer(connectionString);
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
}, ServiceLifetime.Singleton, ServiceLifetime.Transient);
}, ServiceLifetime.Scoped);

// chat
services.AddScoped<IChatRepository, ChatRepository>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public async Task CommitTransactionAsync()
}

}

public void Dispose()
{
Dispose(true);
Expand Down
15 changes: 9 additions & 6 deletions NotaionWebApp/Notaion/Controllers/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Notaion.Application.Services;
using Notaion.Application.Interfaces.Services;
using Microsoft.AspNetCore.Authorization;
using System;

namespace Notaion.Controllers
{
Expand All @@ -28,12 +29,12 @@ public ChatController(ApplicationDbContext context, IHubContext<ChatHub> hubCont
this.chatService = chatService;
}

[HttpGet("test-genaric-repo")]
public async Task<IActionResult> GetChatWithGenaricRepo()
{
var chats = await chatService.GetChatsAsync();
return Ok(chats);
}
//[HttpGet("test-genaric-repo")]
//public async Task<IActionResult> GetChatWithGenaricRepo()
//{
// var chats = await chatService.GetChatsAsync();
// return Ok(chats);
//}

//[Authorize]
[HttpGet("get-chats")]
Expand All @@ -60,6 +61,8 @@ public async Task<IActionResult> AddChat([FromBody] CreateChatDto chatDto)
{
var createdChat = await this.chatService.CreateChatAsync(chatDto);

await _hubContext.Clients.All.SendAsync("ReceiveMessage", createdChat.UserName, createdChat.Content);

return Ok(createdChat);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ by editing this MSBuild file. In order to learn more about this please visit htt
<PropertyGroup>
<TimeStampOfAssociatedLegacyPublishXmlFile />
<EncryptedPassword>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA45ACkv6Ev0Gy7utx8HyVkgAAAAACAAAAAAAQZgAAAAEAACAAAABSm0dADuKEoSXI2PM3/C+djjsZNaNJvaNktK2zzOh0ZQAAAAAOgAAAAAIAACAAAAAaubSe329ikteIzbdUehSGkeEFWcMirIFoj/tBJlG3PCAAAAAaOwJII3B0tuPaPOzYnGrfQAgIQnX5FDaCdhlVr8BQDEAAAADxwckrnekLCzuMBtAKkP1cCWMOulRqdqFNLxcPxe9HXD/Y0JACDx7eUDw/7grdO/SQQKIkbvxPSZZdbFnGYkiS</EncryptedPassword>
<History>True|2024-11-18T01:56:26.6539288Z||;False|2024-11-18T08:54:38.8724697+07:00||;True|2024-11-17T23:02:34.2326203+07:00||;True|2024-11-17T22:58:09.9977191+07:00||;True|2024-11-14T11:37:13.0792751+07:00||;True|2024-10-28T19:07:16.1054653+07:00||;True|2024-10-08T17:12:03.4740526+07:00||;</History>
<History>True|2024-11-22T12:11:24.9616986Z||;True|2024-11-22T19:01:42.6927776+07:00||;True|2024-11-22T18:40:57.6369725+07:00||;True|2024-11-22T18:29:27.3414695+07:00||;True|2024-11-18T08:56:26.6539288+07:00||;False|2024-11-18T08:54:38.8724697+07:00||;True|2024-11-17T23:02:34.2326203+07:00||;True|2024-11-17T22:58:09.9977191+07:00||;True|2024-11-14T11:37:13.0792751+07:00||;True|2024-10-28T19:07:16.1054653+07:00||;True|2024-10-08T17:12:03.4740526+07:00||;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

0 comments on commit 2c78d14

Please sign in to comment.