SOLID & Design Patterns Interview Question #106

What is the Dependency Rule in Clean Architecture?

Architectural Patterns, Application Boundaries & Distributed Design Patterns Senior Advanced

Quick Interview Answer

The Dependency Rule states that source-code dependencies should point toward inner, more stable policy layers. Inner layers should not know about outer frameworks or infrastructure implementations.

Detailed Explanation

The Dependency Rule states that source-code dependencies should point toward inner, more stable policy layers. Inner layers should not know about outer frameworks or infrastructure implementations.

For example, an application service can depend on an IOrderRepository interface defined in the core, while an EF Core repository in Infrastructure implements that interface.

Code Example

// Application/Core
public interface IOrderRepository
{
    Task<Order?> GetAsync(Guid id);
}

// Infrastructure depends inward.
public class EfOrderRepository : IOrderRepository
{
}