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 large software projects where many developers work on the same code base one of the biggest challenges is to get consistency in code, to create development patterns for common problems, so you can control the complexity and size of the system.
In this presentation I will show how we can achieve consistency 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.
13. Quality through Structure
You enforce consistency with structure
Create a structure that makes difficult to write bad
code rather then code that follows the design
You use assemblies and references among them to
enforce rules
Hide external frameworks to enforce the way they are
used
Enforce Constructor Dependency Injection and
encourage Programming Against Interfaces
13
26. AppBoot: DI Abstractions & Type Discovery
26
<<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
27. AppBoot Separates DI Configuration from DI Use27
iQuarcAppBoot
<<Attribute>><<Attribute>>
ServiceAttribute
+LogError()
Bootstrapper
+Run()
<<Internal>><<Internal>>
DependencyContainerAdapter
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
}
}