Skip to main content
fixing spelling error for clarity
Link
VoiceOfUnreason
  • 34.7k
  • 2
  • 45
  • 84

Can the Application Service layer create an instance of a nonenon aggregate root?

added 442 characters in body
Source Link
w0051977
  • 7.1k
  • 8
  • 67
  • 96

Say I have an aggregate root called Customer. In this example, the customer has a collection of invoices.

Is it ever "acceptable" for the Application Service layer to create an instance of the Invoice class? The invoice class is not the aggregate root.

I realise it is not "acceptable" for a none aggregate root from another aggregate to access the Customer class, however I wandered if this also applies to the Application Service.

I am talking from the perspective of a DDD purist. I realise that DDD is not always the best choice to solve a problem - I am just trying to improve my thinking in this specific area.

Update

Please see the code below:

public class InvoiceService
{
 
 Invoice Invoice;

 public InvoiceService(Invoice invoice)
 {
   Invoice=invoice;
 }

 public void DoSomething()
 {
   Invoice.DoSomething();
 }

}

I am asking if it is "acceptable" to access the Invoice domain object from an application service even though it is not an aggregate root i.e. must all Invoice actions go through Customer.Invoices instead of Invoices.

Say I have an aggregate root called Customer. In this example, the customer has a collection of invoices.

Is it ever "acceptable" for the Application Service layer to create an instance of the Invoice class? The invoice class is not the aggregate root.

I realise it is not "acceptable" for a none aggregate root from another aggregate to access the Customer class, however I wandered if this also applies to the Application Service.

I am talking from the perspective of a DDD purist. I realise that DDD is not always the best choice to solve a problem - I am just trying to improve my thinking in this specific area.

Say I have an aggregate root called Customer. In this example, the customer has a collection of invoices.

Is it ever "acceptable" for the Application Service layer to create an instance of the Invoice class? The invoice class is not the aggregate root.

I realise it is not "acceptable" for a none aggregate root from another aggregate to access the Customer class, however I wandered if this also applies to the Application Service.

I am talking from the perspective of a DDD purist. I realise that DDD is not always the best choice to solve a problem - I am just trying to improve my thinking in this specific area.

Update

Please see the code below:

public class InvoiceService
{
 
 Invoice Invoice;

 public InvoiceService(Invoice invoice)
 {
   Invoice=invoice;
 }

 public void DoSomething()
 {
   Invoice.DoSomething();
 }

}

I am asking if it is "acceptable" to access the Invoice domain object from an application service even though it is not an aggregate root i.e. must all Invoice actions go through Customer.Invoices instead of Invoices.

Source Link
w0051977
  • 7.1k
  • 8
  • 67
  • 96

Can the Application Service layer create an instance of a none aggregate root?

Say I have an aggregate root called Customer. In this example, the customer has a collection of invoices.

Is it ever "acceptable" for the Application Service layer to create an instance of the Invoice class? The invoice class is not the aggregate root.

I realise it is not "acceptable" for a none aggregate root from another aggregate to access the Customer class, however I wandered if this also applies to the Application Service.

I am talking from the perspective of a DDD purist. I realise that DDD is not always the best choice to solve a problem - I am just trying to improve my thinking in this specific area.