Clean Architecture as a term is around for a while. However, the path to implement it is not always clear nor easy to follow. When projects fail for reasons that are primary technical, the reason is often uncontrolled complexity. The complexity goes out of hand when the code lacks structure, when it lacks Clean Architecture.
In this presentation, I will show how to achieve consistency by
implementing Clean Architecture through structure, rather than relying on discipline only. We will look at some basic building blocks of an application infrastructure which will enforce the way dependencies are created, how dependency injection is used or how separation of the data access concerns is enforced.
11. https://onCodeDesign.com/implementing-clean-architecture
Implementing Clean Architecture through
Structure
• Hide external frameworks to enforce the way they are used
• Use assemblies and references among them to enforce rules
• Enforce Constructor Dependency Injection that encourages
Programming Against Interfaces
Create a structure that makes it difficult to write bad code and it makes it easy to write good code,
code that follows the architecture and the design
15. https://onCodeDesign.com/implementing-clean-architecture
DIP to Enforce Separation of Data Access Concern
<<Interface>>
IDbContextFactory
+CreateContext()
Database
<<DTO>>
Customer<<DTO>>
Order<<DTO>>
Person
UnitOfWork
Repository DbContextFactory
<<Interface>>
TDataModel
IRepository, IUnitOfWork
+GetEntities()
+SaveEntities()
16. https://onCodeDesign.com/implementing-clean-architecture
AppBoot: DI Abstractions & Type Discovery
<<Interface>>
TDataModel
<<Interface>>
TDataModel
IEntityInterceptor
+OnLoad()
+OnSaving()
<<Interface>>
TDataModel
<<Interface>>
TDataModel
IDbContextFactory
+CreateContext()
Database
<<DTO>><<DTO>>
Customer<<DTO>><<DTO>>
Order<<DTO>><<DTO>>
Person
<<DTO>>
Customer<<DTO>>
Order<<DTO>>
Person
UnitOfWork
Repository
UnitOfWork
Repository DbContextFactory
<<Attribute>><<Attribute>>
ServiceAttribute
17. https://onCodeDesign.com/implementing-clean-architecture
<<Attribute>>
ServiceAttribute
+ServiceAttribute(interface : Type )
Bootstrapper
+Run()
<<Internal>>
DependencyContainerAdapter
iQuarcAppBoot
AppBoot Hides the DI Framework under Abstractions
public interface IPriceCalculator
{
int CalculateTaxes(Order o, Customer c);
int CalculateDiscount(Order o, Customer c);
}
[Service(typeof(IPriceCalculator), Lifetime.Instance)]
interal class PriceCalculator : IPriceCalculator
{
public int CalculateTaxes(Order o, Customer c)
{
return 10; // do actual calculation
}
public int CalculateDiscount(Order o, Customer c)
{
return 20; // do actual calculation
}
}
26. https://onCodeDesign.com/implementing-clean-architecture
Implementing Clean Architecture through Structure
External
Interfaces
UI Frameworks
Devices
Controllers
EntitiesEntities
Use Cases
<<Attribute>><<Attribute>>
ServiceAttribute
RepositoryImpl
+ GetEntities<T>() : IQueriable()
+ SaveChanges()
Hide external frameworks to enforce the way they are used
Use assemblies and references among them to enforce rules
Enforce Constructor Dependency Injection that encourages Programming Against Interfaces
/iQuarc
iQuarc
onCodeDesign.com/training