Use an extension method for fetching a required user in a common way (#15953)

This commit is contained in:
Kenn Jacobsen
2024-04-02 11:20:05 +02:00
committed by GitHub
parent 96f2b17c5a
commit 1866b61e12
7 changed files with 26 additions and 17 deletions

View File

@@ -0,0 +1,11 @@
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Services;
namespace Umbraco.Cms.Core.Extensions;
public static class UserServiceExtensions
{
public static async Task<IUser> GetRequiredUserAsync(this IUserService userService, Guid key)
=> await userService.GetAsync(key)
?? throw new InvalidOperationException($"Could not find user with key: {key}");
}