An attempt to send messages out of the scope

This commit is contained in:
TheXamlGuy
2024-05-12 20:21:55 +01:00
parent 837e249c64
commit 2842fc7108
11 changed files with 71 additions and 63 deletions
+10 -4
View File
@@ -1,5 +1,6 @@
using Bitvault.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Toolkit.Foundation;
namespace Bitvault;
@@ -14,16 +15,21 @@ public class CreateItemHandler(IDbContextFactory<ContainerDbContext> dbContextFa
{
try
{
using ContainerDbContext context = dbContextFactory.CreateDbContext();
EntityEntry<ItemEntry>? result = null;
await Task.Run(async () =>
{
using ContainerDbContext context = dbContextFactory.CreateDbContext();
await context.AddAsync(new Data.Item { Name = configuration.Name }, cancellationToken);
result = await context.AddAsync(new ItemEntry { Name = configuration.Name }, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
}, cancellationToken);
await publisher.Publish(Activated.As(configuration));
return true;
if (result is not null)
{
await publisher.Publish(Activated.As(new Item { Id = result.Entity.Id }), cancellationToken);
return true;
}
}
catch
{