Geekn
Geekn

Reputation: 2882

Where does a Factory pattern implementation class reside in clean architecture for DDD

I'm trying to follow clean architecture with DDD using a solution that has the following three project types:

I have a factory class MapperFactory that implements an interface IMapperFactory which returns an IMapperService based on a MapType passed into the factory. Implementations of IMapperService reside in the Core layer.

I'm struggling to understand where the Factory implementation classes should reside. All my repositories are implemented in the infrastructure project but domain services are implemented in the Core project per clean architecture guidelines (at least how I read them)

I feel like the implementation for the factory should be in the core project because that's where all the implementations that it needs to create reside, but not sure. If it should be in the core project, what type of object would it be since it's not an entity, service, or interface?

Upvotes: 5

Views: 3986

Answers (1)

anick chowdhury
anick chowdhury

Reputation: 191

What is the purpose of MapperFactory?

If your MapperFactory maps database object to(and from) domain object then they should go to Infrastructure project(as your repository implementations reside there).

If your mapper maps domain object to(and from) view model then they reside in API project.

If your model resides inside Core services e.g. you don't want to expose your domains to the outside world and you have some Contracts in services to communicate with external world then your MapperFactory should reside inside Core(assuming MapperFactory will map domains to (and from) Contracts.

Upvotes: 8

Related Questions