Ish Thomas
Ish Thomas

Reputation: 2440

Abstract Factory Pattern in Onion Architecture

Good morning, My question is about Visual Studio project/catalog structure. I'm creating a simple project and I want to adopt Onion Architecture there. I have few layers (projects): MyProject.Domain (with Enums, Entites, Interfaces), MyProject.API, MyProject.Infrastructure.DependecyResolution, MyProject.Client.WPF

I want to use Abstract Factory Pattern. I have factory class, and few product classes.

My "product's" interfaces are in Domain->Interfaces, my "product's" implementations are in Domain->Entites. Where in my Visual Studio Solution, should I put interfaces and implementations of Factories (that will create those products)?

My question is: Is Factory interface or Factory concrete implementation part of Domain in Onion Arch.? Or should I create another project for factories? This question is more about good programming practices, maintaining Visual Studio solution clean and tidy.

Upvotes: 0

Views: 1473

Answers (3)

my idea is make Ifactories folder in domain project in core of software,but bring implementation of them in upper layers

benefit of bring interfaces in core is upper layers can use them

benefit of bring implementation in upper layers is encapsulating implementation

Upvotes: 0

Fuhrmanator
Fuhrmanator

Reputation: 12882

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.

Upvotes: 2

Chris Halcrow
Chris Halcrow

Reputation: 31950

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.

Upvotes: 3

Related Questions