Base solution for your next web application
Open Closed

Strange Unit of Work Behavior with NotificationPublisher #8394


User avatar
0
cyklussoftware created

Hello,

I am in the process of upgrading from ASP.NET Zero v7.1.0 with .NET Core 2.2 and Angular to ASP.NET Zero v8.1.0 with .NET Core 3.1 with Angular. The upgrade is going well and I am in the process of updating my queries to be compatible with EF Core 3.

I just came across some strange behavior with the Current Unit of Work and the NotificationPublisher. I'll show example code below:

Announcement is an AuditedEntity.

I have this line in my AnnouncementsAppService.Create(...) method:

await _announcementRepository.InsertAsync(announcement);

Later in the Create method, I have this line which calls a separate DomainService:

await _announcementDomainService.SendToAppropriateUsers(announcement, matchingAliases);

SendToAppropriateUsers is a public async Task. In this method, I run await _notificationPublisher.PublishAsync(......) with some parameters. Notifications are published successfully and I see a web notification. When I look at my dbo.Announcements table in the database, the Announcement is saved, but the CreatorUserId field is NULL. The CreationTime column is correctly set.

I figured out that if I call await CurrentUnitOfWork.SaveChangesAsync(); anywhere before I call await _notificationPublisher.PublishAsync(......), the CreatorUserId is saved correctly (it is not null). I can also remove await _notificationPublisher.PublishAsync(......) and it will save correctly. I tried making my method virtual with the [UnitOfWork] attribute. This resulted in the same behavior as I've described.

This line in the ASP.NET Boilerplate NotificationPublisher.cs file (see line here) saves the Unit of Work the same way I tried, but the Announcement.CreatorUserId column is still NULL.

Do you know why this is only happening when I run await _notificationPublisher.PublishAsync(......) before I've saved the CurrentUnitOfWork?

Thanks!


2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    It seems strange, can you share more code so that I can reproduce the problem?

  • User Avatar
    0
    ismcagdas created
    Support Team

    This issue is closed because of no recent activity. Please create a new issue if you are still having this problem.