users/src/Nocr.Users.AppServices/Users/User.cs
Sergey Nazarov fe9edd891b Add user
2024-03-23 01:11:25 +04:00

35 lines
971 B
C#

namespace Nocr.Users.AppServices.Users;
public sealed class User
{
public long Id { get; set; }
public string Username { get; private set; }
private List<UserIdentity> _identities = new List<UserIdentity>();
public IReadOnlyCollection<UserIdentity> Identities => _identities;
private User(string username, params UserIdentity[] identities)
{
Username = username;
// TODO: Check that there is no repeating identity types
_identities.AddRange(identities);
}
public static User Initialize(string username, params UserIdentity[] identities)
{
if (string.IsNullOrWhiteSpace(username))
{
throw new ArgumentNullException(nameof(username));
}
if (username.Length is < 5 or > 32)
{
throw new ArgumentException("Username length should be between 5 and 32 symbols", username);
}
return new User(username, identities);
}
}