Вариант 1:
Код: Выделить всё
public async Task Like(LikeDto dto)
{
var _ = svc.ExecuteDb(async (context) =>
{
var (rating, liked) = await likeAndSave(context, dto.Liked);
await sendEvents(dto.Id, liked);
});
await Task.CompletedTask;
}
Код: Выделить всё
public async Task Like(LikeDto dto)
{
var _ = svc.ExecuteDb(async (context) =>
{
var (rating, liked) = await likeAndSave(context, dto.Liked);
await sendEvents(dto.Id, liked);
});
await Task.FromResult(_);
}
Код: Выделить всё
public async Task Like(LikeDto dto)
{
await Task.Run(() =>
{
var _ = svc.ExecuteDb(async (context) =>
{
var (rating, liked) = await likeAndSave(context, dto.Liked);
await sendEvents(dto.Id, liked);
});
});
}
Код: Выделить всё
public class SercicesProvider where T : DbContext
{
private readonly IServiceProvider _services;
public SercicesProvider(IServiceProvider svc)
{
_services = svc;
}
public async Task ExecuteDb(Func action)
{
using (var scope = _services.CreateScope())
{
var service = scope.ServiceProvider.GetRequiredService();
await action(service);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... and-forget