Abstract Factory Pattern in Onion Architecture

Solution 1:

There isn't a single correct answer. Maybe you can create a folder 'core' where you put all of your core code. There's nothing wrong with just creating an 'interfaces' folder inside this and it's common to see a folder called 'entities' containing the various data classes.

Solution 2:

My question is: Is Factory interface or Factory concrete implementation part of Domain in Onion Arch.?

I'm not an expert in Onion Architecture philosophy, but there are a few arguments to put the Factories in the same package as the products:

  • Factories can be visible whereas the products can be package visible (meaning outside clients won't be able to directly access products; they have to go through the factories),
  • Package cohesion via the REP (Reuse Release Equivalency Principle) of Robert Martin says "The granule of reuse is the granule of release." If you don't bundle factories with their products, the package won't be reusable easily.