ardalis / Specification

Base class with tests for adding specifications to a DDD model
MIT License
1.95k stars 245 forks source link

Apply Entity and Aggregate Domain-Driven Design approach to Specification and Repository #384

Closed elyosemite closed 10 months ago

elyosemite commented 10 months ago

In a Domain-Driven Design approach, we have aggregates and entities, so it is common to see markup interfaces such as IAggregateRoot and IEntity.

That being said, it wouldn't be interesting to think about Specification applied to an entity, so you've already considered - in the Ardalis.Specification nuget - using it in the following way:

public interface ISpecification<T> where T : IEntity.

And the second solution would be for repositories, in which it would only allow using IAggregateRoot.

public interface IReadRepositoryBase<T> where T : IAggregateRoot.

fiseni commented 10 months ago

Hi @elyosemite,

That's way too opinionated. Forcing everyone to apply IEntity to all entities will piss off everyone. This library is agnostic to how you organize your codebase, or what architectural decisions you've made. That's up to you as a consumer. You may not even be using repositories, and that's fine; use specifications without repositories.

Yes, the specifications play nicely with repositories. And if you choose to do so, then please check our samples (in the sample folder in this repo). In Sample3 we have an example implementation using read and write repositories; where the write repository is constrained to only aggregate roots (entities marked with IAggregateRoot).

elyosemite commented 10 months ago

Awesome!!! Thanks for the observations. <3