Using ISpecification in core layer violating OOP

161 views Asked by At

Using ISpecification (from the Ardalis.Specification package) in the Core layer, doesn't cause the tight coupling to a library? I think it's adding tight coupling to a specific library, and it violates OOP principles and impacts future development on it.

1

There are 1 answers

0
ssmith On

When following SOLID principles and specifically the Dependency Inversion Principle along with Clean Architecture (aka Onion, Hexagonal, Ports and Adapters, etc.), it's best not to have dependencies flowing from your high level business logic (domain layer) classes and types to your low level implementation details. I think this is what you're concerned about.

However, it can be useful to leverage libraries that only contain in-memory functionality and do not add any coupling to infrastructure concerns. For instance, it's not unusual in my projects to have dependencies from my Core domain project to packages like these:

None of these have dependencies on specific implementation details.

That said, I would not add a reference to or depend on implementation specific packages like:

Part of the reason why these are separate packages is so that you can leverage the in-memory functionality of these packages while keeping the infrastructure-specific implementations separate (and only referencing these as and when appropriate).