اعتبارسنجی Domain Model
نویسنده: سالار ربال
تاریخ: ۱۳۹۸/۰۵/۲۸ ۱۲:۳
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
public interface ICustomerUniquenessChecker
{
bool IsUnique(Customer customer);
} public Customer(string email, string name, ICustomerUniquenessChecker customerUniquenessChecker)
{
this.Email = email;
this.Name = name;
var isUnique = customerUniquenessChecker.IsUnique(this);
if (!isUnique)
{
throw new BusinessRuleValidationException("Customer with this email already exists.");
}
this.AddDomainEvent(new CustomerRegisteredEvent(this));
}
public class Customer
{
public string Email { get; private set; }
public string Name { get; private set; }
private Customer(email, name)
{
Email = email;
Name = name;
}
public static Result<Customer> New(string email, string name, INewCustomerPolicy policy)
{
var isUnique = policy.IsUnique(email);
if (!isUnique)
{
return Result.Fail<Customer>("Customer with this email already exists.");
}
var customer = new Customer(email, name);
//customer.AddDomainEvent(new CustomerRegistered(customer));
return Result.Ok(customer);
}
}