How domain model capture business logic / domain logic since i cannot access repository?
I see many posts saying that domain model = business objects
But Business objects live in application layer (service layer "not domain services") where they constructed after a repository call and returned to the view
if that is true, then why define domain models in domain layer and isolate them since most of the methods require to access repositories and not just have business objects defined in application layer? e.g ReceivePayment_Business_Object?
I'm sure somewhere i've been lost...
Trying to follow ddd
I have the following domain model ( Receive Payment)
public class ReceivePayment
{
public string ID { get; private set; }
//this should be auto complete when customer change
public string AccountID { get; private set; }
public string DepositToAccountID { get; set; }
public EntityContact Customer { get; private set; }
public decimal ExchangeRate { get; private set; }
public CurrencyItem BaseCurrency { get; }
public void SetCustomer(EntityContact contact)
{
//business rules / domain logic
if (contact.Type != EntityType.Customer)
throw new Exception("Entity must be of type customer");
if (contact.IsInactive == true)
throw new Exception("Cannot set Inactive customer.");
if (BaseCurrency.ID == contact.CurrencyID)
{
SetExRate(1);
}
else
{
//get latest ex rate from database based on customer currency ID
//but domain model not allow us to access IRepositories
//Then how do i procceed?
}
//AccountID must be auto set
//I need access to Customer and get back property DefaultAccountID to accociate with AccountID
//How DDD solve this ?
}
public void SetExRate(decimal ex_rate)
{
ExchangeRate = ex_rate;
Recalculate();
}
public void Recalculate()
{
// Calulcations things
}
For reference this how our accounting solution looks like
Domain Layer ( isolated - reference nothing )
- Irepositories
- Domain Models
DAL Layer (Infrastructure)
- Reference Domain Layer
- Repositories implementation
- Persistence mechanism ( entity framework or ado.net sql)
Application Layer (Service Layer)
- Reference DAL and just orchestrate the flow of the application
- Reference Domain Layer
UI Layer (reference application Layer & Domain Layer)
- WPF
- Andoird (Xamarin forms)