Can an AppUser : IdentityUser get linked to an Employee-entity while keeping separation of concerns with Dependency inversion in Clean architecture

I have chosen to define ApplicationUser class like this in the infrastructure-layer:

namespace MySolution.Infrastructure.Context
{
    // Add profile data for application users by adding properties to the ApplicationUser class
    public class ApplicationUser : IdentityUser
    {
        public EmployeeId EmployeeId { get; set; }
        public Employee Employee { get; set; }
    }

}

I also created a table for connecting a user to an employee

namespace MySolution.Infrastructure.Context
{
    public class EmployeeUserMap
    {
        public string ApplicationUserId { get; set; }
        public ApplicationUser ApplicationUser { get; set; }
        public EmployeeId EmployeeId { get; set; }
        public Employee Employee { get; set; }
    }
}

and here’s the entity from my domain layer:


namespace MySolution.Domain.Entities
{
    public class Employee
    {
        //empty constructor
        private Employee() { } // Required by EF core
        
        //properties
        public EmployeeId Id { get; init; }
        public required VatNumber WorkplaceVAT { get; init; }
        public required string EmployeeName { get;  set; }
        public required Address Address { get;  set; }
        public required ContactInfo ContactInfo { get;  set; }
        public required UserRole Role { get; set; }
        public string? ApplicationUserId { get; set; }
        public CompanyId CompanyId { get; init; }

        //Navigational properties
        public Company Company { get; set; }

        [SetsRequiredMembers]
        public Employee(string name, ContactInfo contactInfo, Address address, VatNumber workplaceVAT, UserRole role, CompanyId companyId, string applicationUserId)
        {
            Id = EmployeeId.Create();
            EmployeeName = name ?? throw new ArgumentNullException(nameof(name));
            ContactInfo = contactInfo ?? throw new ArgumentNullException(nameof(contactInfo));
            Address = address ?? throw new ArgumentNullException(nameof(address));
            WorkplaceVAT = workplaceVAT ?? throw new ArgumentNullException(nameof(workplaceVAT));
            Role = role;
            CompanyId = companyId;
            ApplicationUserId = applicationUserId;
            Validate(this);
        }

        private static void Validate(Employee employee)
        {
            var context = new ValidationContext(employee);
            Validator.ValidateObject(employee, context, validateAllProperties : true);
        }
        public void ChangeContactDetails(ContactInfo newContactDetails)
        {
            ContactInfo = newContactDetails ?? throw new ArgumentNullException(nameof(newContactDetails));
        }
        public void ChangeAddress(Address newAddress) 
        { 
            Address = newAddress ?? throw new ArgumentNullException(nameof(newAddress)); 
        }
    }
}

I can’t wrap my head around how to keep the domain layer independent but to pass an ApplicationUserId to the entity. I want a one-to-one relationship between Employee-ApplicationUser, and I want to be able to create an Employee first and have the applicationId nullable, and next i want to be able to register a user only if the Employee with same mail exists.

    public async Task RegisterUser(EditContext editContext)
    {
        var employee = await _mediator.Send(new GetEmployeeByEmailQuery(Input.Email), default);

        if (employee != null)
        {
            var user = CreateUser();

            await UserStore.SetUserNameAsync(user, Input.Email, CancellationToken.None);
            var emailStore = GetEmailStore();
            await emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None);

            user.EmployeeId = employee.Id;

            var result = await UserManager.CreateAsync(user, Input.Password);

            if (!result.Succeeded)
            {
                identityErrors = result.Errors;
                return;
            }

            await UserManager.UpdateAsync(user);

            employee.ApplicationUserId = user.Id;

            await _mediator.Send(new UpdateEmployeeCommand(new VatNumber(employee.WorkplaceVat), employee.Name, AddressMapper.ToValueObject(employee.Address), ContactInfoMapper.ToValueObject(employee.ContactInfo), employee.ApplicationUserId!, employee.Role, employee.CompanyId), default);

            Logger.LogInformation("User created a new account with password.");



            var userId = await UserManager.GetUserIdAsync(user);
            var code = await UserManager.GenerateEmailConfirmationTokenAsync(user);
            code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
            var callbackUrl = NavigationManager.GetUriWithQueryParameters(
                NavigationManager.ToAbsoluteUri("Account/ConfirmEmail").AbsoluteUri,
                new Dictionary<string, object?> { ["userId"] = userId, ["code"] = code, ["returnUrl"] = ReturnUrl });

            await EmailSender.SendConfirmationLinkAsync(user, Input.Email, HtmlEncoder.Default.Encode(callbackUrl));

            if (UserManager.Options.SignIn.RequireConfirmedAccount)
            {
                RedirectManager.RedirectTo(
                    "Account/RegisterConfirmation",
                    new() { ["email"] = Input.Email, ["returnUrl"] = ReturnUrl });
            }

            await SignInManager.SignInAsync(user, isPersistent: false);
            RedirectManager.RedirectTo(ReturnUrl);
        }
        else
        {
            identityErrors = new List<IdentityError> { new IdentityError { Description = "Employee not found for the provided email." } };
        }
    }

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật