https://onCodeDesign.com/DevTalks2018
Enforce Consistency through
Application Infrastructure
Florin Coroș
.com
www.iQuarc.com | www.InfiniSwiss.com | onCodeDesign.com
florin.coros@iquarc.com
@florincoros
https://onCodeDesign.com/DevTalks2018
About me
@florincoros
Co-Founder & Partner
Partner
.com
Co-Founder & Partner
https://onCodeDesign.com/DevTalks2018
Why Is Consistency the Key?
3
https://onCodeDesign.com/DevTalks2018
Impeded by Others’ Code?
4
https://onCodeDesign.com/DevTalks2018
Different Solutions to the Same Problem
5
https://onCodeDesign.com/DevTalks2018
Which one is the ONE?
6
https://onCodeDesign.com/DevTalks2018
Cost of Change
Wrong approach consistently repeated
in all of the application screens
vs
Uniquely new approach in all of the
application screens
7
https://onCodeDesign.com/DevTalks2018
Managing Complexity
when projects do fail for reasons that are primarily
technical, the reason is often
uncontrolled complexity
8
https://onCodeDesign.com/DevTalks2018
Controlling the Complexity
uniqueness consistency
9
https://onCodeDesign.com/DevTalks2018
Rules Are Easy to Ignore
Quick and Dirty
vs
The only way to go fast, is to go well!
10
https://onCodeDesign.com/DevTalks2018
Quality through Discipline
11
https://onCodeDesign.com/DevTalks2018
Seniors May Be Overwhelmed with Review
12
https://onCodeDesign.com/DevTalks2018
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
https://onCodeDesign.com/DevTalks2018
Assure Consistency in Using External Library by
Hiding It
Exception Wrappers Decorators
<<Interface>>
API Interfaces<<static class>>
Log
+LogError()
+LogWarining()
14
https://onCodeDesign.com/DevTalks2018
public interface ILog
{
void Info(string message, params object[] args);
void Warn(string message, params object[] args);
void Error(string message, Exception ex);
}
Enforces Separation of Concerns
The application code only knows about ILog
Once I is defined we can develop screens and call
this interface to log traces or errors
The real implementation can be done later
If logging needs changes, we can modify the
interfaces at once in all places it is used
The implementation is in only one place, so one place to
change only
15
https://onCodeDesign.com/DevTalks2018
Encapsulate Data Access Concerns
<<Interface>>
TDataModel
IRepository
+GetEntities<TDataModel>()
<<Interface>>
TDataModel
IUnitOfWork
+GetEntities<TDataModel>()
+SaveChanges()
Database
Repository UnitOfWork
<<Stereotype>>
<<DTO>>
Order
<<DTO>>
Person
[Service(typeof (IRepository))]
internal class EfRepository : IRepository, IDisposable
{
private readonly IDbContextFactory contextFactory;
private readonly IInterceptorsResolver interceptorsResolver;
private DbContext context;
private readonly IEnumerable<IEntityInterceptor> interceptors;
public EfRepository(IDbContextFactory contextFactory,
IInterceptorsResolver resolver)
{
this.contextFactory = contextFactory;
this.interceptorsResolver = interceptorsResolver;
this.interceptors =
resolver.GetGlobalInterceptors();
}
... iQuarcDataAccess
16
https://onCodeDesign.com/DevTalks2018
public interface IRepository
{
IQueryable<TDbEntity> GetEntities<TDbEntity>() where TDbEntity : class;
IUnitOfWork CreateUnitOfWork();
}
public interface IUnitOfWork : IRepository, IDisposable
{
void SaveChanges();
void Add<T>(T entity) where T : class;
void Delete<T>(T entity) where T : class;
void BeginTransactionScope(SimplifiedIsolationLevel isolation);
}
Create Separated Patterns for Read-Only and
Read-Write
17
https://onCodeDesign.com/DevTalks2018
Patterns for Read-Only data
public class OrdersController : Controller
{
private readonly IRepository repository;
public OrdersController(IRepository repository)
{
this.repository = repository;
}
public IActionResult Index(string customer)
{
var orders = repository.GetEntities<SalesOrderHeader>()
.Where(soh => soh.Customer.Person.LastName == customer)
.Select(soh => new OrdersListViewModel
{
CustomerName = customer,
Number = soh.SalesOrderNumber,
SalesPersonName = soh.SalesPerson,
DueDate = soh.DueDate,
});
return View(orders);
}
...
}
18
https://onCodeDesign.com/DevTalks2018
Patterns for Read-Write data
public class OrdersController : Controller
{
...
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult PlaceOrder(OrderRequestViewModel model)
{
...
using (IUnitOfWork uof = repository.CreateUnitOfWork())
{
SalesOrderHeader order = uof.GetEntities<SalesOrderHeader>()
.FirstOrDefault(o => o.CustomerID == c.ID && o.OrderDate.Month == DateTime.Now.Month);
if (order == null)
{
order = new SalesOrderHeader {Customer = c};
uof.Add(order);
}
AddRequestToOrder(model, order);
uof.SaveChanges();
}
...
}
19
https://onCodeDesign.com/DevTalks2018
Consistency Creates Optimizations Opportunities
internal class EfRepository : IRepository, IDisposable
{
public IQueryable<T> GetEntities<T>() where T : class
{
return Context.Set<T>().AsNoTracking();
}
public IUnitOfWork CreateUnitOfWork()
{
return new EfUnitOfWork(contextFactory, interceptorsResolver);
}
private sealed class EfUnitOfWork : IUnitOfWork
{
private DbContext context;
private TransactionScope transactionScope;
private readonly IDbContextFactory contextFactory;
public EfUnitOfWork(IDbContextFactory contextFactory, IInterceptorsResolver resolver)
{
this.contextFactory = contextFactory;
this.interceptorsResolver = interceptorsResolver;
}
}
20
https://onCodeDesign.com/DevTalks2018
Create Development Patters in how Data is Accessed
21
https://onCodeDesign.com/DevTalks2018
Enforce Separation of Data Access Concerns
<<Interface>>
TDataModel
IRepository
+GetEntities<TDataModel>()
<<Interface>>
TDataModel
IUnitOfWork
+GetEntities<TDataModel>()
+SaveChanges()
Database
Repository UnitOfWork
<<Stereotype>>
<<DTO>>
Order<<DTO>>
Person
22
https://onCodeDesign.com/DevTalks2018
DIP to Enforce Separation of Data Access Concern
<<Interface>>
TDataModel
IEntityInterceptor
+OnLoad()
+OnSaving()
<<Interface>>
TDataModel
IDbContextFactory
+CreateContext()
Database
<<DTO>>
Customer<<DTO>>
Order <<DTO>>
Person
DbContextFactoryUnitOfWork
Repository
23
https://onCodeDesign.com/DevTalks2018
DIP to Move OnSave & OnLoad Logic out of Data Access
<<Interface>>
TDataModel
IEntityInterceptor
+OnLoad()
+OnSaving()
<<Interface>>
TDataModel
IDbContextFactory
+CreateContext()
DbContextFactoryUnitOfWork
Repository
24
https://onCodeDesign.com/DevTalks2018
AppBoot: DI Abstractions & Type Descovery
<<Attribute>>
ServiceAttribute
IModule
<<Interface>>
TDataModel
IEntityInterceptor
+OnLoad()
+OnSaving()
<<Interface>>
TDataModel
IRepository
Database
<<DTO>>
Customer<<DTO>>
Order<<DTO>>
Person
DbContextFactoryUnitOfWork
Repository
<<Interface>>
TDataModel
IUnitOfWork
25
https://onCodeDesign.com/DevTalks2018
AppBoot Enforces Constructor Dependency Injection
<<Attribute>>
ServiceAttribute
+ ServiceAttribute()
+ServiceAttribute(Type contract)
+ ServiceAttribute(Type t, Lifetime lifetime)
Bootstrapper
+Bootstrapper(Assembly[] assemblies)
+Run()
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
}
}
iQuarcAppBoot
26
https://onCodeDesign.com/DevTalks2018
Software systems should separate the startup process, when the application objects are constructed and the
dependencies are “wired” together, from the runtime logic that takes over after startup
<<Interface>>
IModule
+ Initialize()
Application
+ Initialize()
*
+ Modules[]
AppModule1
+ Initialize()
AppModule2
+ Initialize()
Enforce Separation of Construction from Use
public static void Main(string[] args)
{
var assemblies = GetApplicationAssemblies().ToArray();
Bootstrapper bootstrapper = new Bootstrapper(assemblies);
bootstrapper.ConfigureWithUnity();
bootstrapper.AddRegistrationBehavior(new ServiceRegistrationBehavior());
bootstrapper.Run();
}
27
https://onCodeDesign.com/DevTalks2018
Patters forCreating Services thatDepend Only onInterfaces
[Service(typeof (IOrderingService))]
public class OrderingService : IOrderingService
{
private readonly IRepository repository;
private readonly IPriceCalculator calculator;
private readonly IApprovalService orderApproval;
public OrderingService(IRepository repository, IPriceCalculator calculator, IApprovalService orderApproval)
{
this.repository = repository;
this.calculator = calculator;
this.orderApproval = orderApproval;
}
public SalesOrderInfo[] GetOrdersInfo(string customerName)
{
var orders = repository.GetEntities<SalesOrderHeader>()
...
return orders.ToArray();
}
public SalesOrderResult PlaceOrder(string customerName, OrderRequest request)
{
...
}
}
28
https://onCodeDesign.com/DevTalks2018
Enforce Constructor DI to Prevent Circular Dependencies
[Service(typeof(IApprovalService))]
class ApprovalService : IApprovalService
{
private readonly IPriceCalculator priceCalculator;
public ApprovalService(IPriceCalculator priceCalculator)
{
this.priceCalculator = priceCalculator;
}
...
}
[Service(typeof (IPriceCalculator), Lifetime.Instance)]
public class PriceCalculator : IPriceCalculator
{
private readonly IApprovalService approvalService;
public PriceCalculator(IApprovalService approvalService)
{
this.approvalService = approvalService;
}
...
}
29
https://onCodeDesign.com/DevTalks2018
Design PatternslikeCompositionorChain of Responsibility30
https://onCodeDesign.com/DevTalks2018
Patters in How Dependencies are Created
31
https://onCodeDesign.com/DevTalks2018
iQuarc iQuarc
Dependencies
Management
Design Patterns in
Service Composition
Enforce Consistency
through Structure
Enforce
Separation of Concerns
Patterns for
Queries & Commands
Interceptors for Queries
& Commands
Enforce Consistency through Application Infrastructure
iQuarcCode-Design-Training
onCodeDesign.comtraining
32
https://onCodeDesign.com/DevTalks2018
Florin Coroș
Co-founder & Partner, iQuarc www.iquarc.com
Co-founder & Partner, InfiniSwiss www.infiniswiss.com
.com
email: florin.coros@iquarc.com
blog: onCodeDesign.com
tweet: @florincoros

More Related Content

PPTX
Enforce Consistency through Application Infrastructure
PDF
Enforce Consistentcy with Clean Architecture
PPTX
Functional Dependency Injection in C#
ODP
CDI @javaonehyderabad
PDF
Interpreter implementation of advice weaving
PDF
Devoxx 2012 (v2)
PDF
Openid+Opensocial
PDF
Implementing Clean Architecture
Enforce Consistency through Application Infrastructure
Enforce Consistentcy with Clean Architecture
Functional Dependency Injection in C#
CDI @javaonehyderabad
Interpreter implementation of advice weaving
Devoxx 2012 (v2)
Openid+Opensocial
Implementing Clean Architecture

Similar to Enforce Consistency through Application Infrastructure (20)

PDF
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
PDF
Enforce Consistency through Application Infrastructure - Florin Coros
PPTX
Enforce Consistency through Application Infrastructure
PDF
Implementing Clean Architecture
PDF
ITCamp 2018 - Florin Coros - ‘Cloud Ready’ Design through Application Softwar...
PPTX
‘Cloud Ready’ Design through Application Software Infrastructure
PPTX
Most Useful Design Patterns
PPTX
Implementing Clean Architecture - Conference Talk
PPTX
Common ASP.NET Design Patterns - Telerik India DevCon 2013
PPTX
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
PDF
Clean architecture with asp.net core
PDF
Smart Client Development
PDF
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
PPTX
CQRS and Event Sourcing
PDF
[FREE PDF sample] Programming Entity Framework DbContext 1st Edition Julia Le...
PPT
Designingapplswithnet
PPT
A clean repository pattern in ef
PDF
Oo aand d-overview
PPTX
Marco Mancuso - Data Context Interaction
PPTX
Refreshing Domain Driven Design
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
Enforce Consistency through Application Infrastructure - Florin Coros
Enforce Consistency through Application Infrastructure
Implementing Clean Architecture
ITCamp 2018 - Florin Coros - ‘Cloud Ready’ Design through Application Softwar...
‘Cloud Ready’ Design through Application Software Infrastructure
Most Useful Design Patterns
Implementing Clean Architecture - Conference Talk
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Clean architecture with asp.net core
Smart Client Development
Dicoding Developer Coaching #31: Android | Menerapkan Clean Architecture di A...
CQRS and Event Sourcing
[FREE PDF sample] Programming Entity Framework DbContext 1st Edition Julia Le...
Designingapplswithnet
A clean repository pattern in ef
Oo aand d-overview
Marco Mancuso - Data Context Interaction
Refreshing Domain Driven Design
Ad

Recently uploaded (20)

PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
PDF
The influence of sentiment analysis in enhancing early warning system model f...
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
Auditboard EB SOX Playbook 2023 edition.
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
PPTX
Internet of Everything -Basic concepts details
PDF
Lung cancer patients survival prediction using outlier detection and optimize...
PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
Co-training pseudo-labeling for text classification with support vector machi...
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PPTX
future_of_ai_comprehensive_20250822032121.pptx
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PPTX
Module 1 Introduction to Web Programming .pptx
Early detection and classification of bone marrow changes in lumbar vertebrae...
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
The influence of sentiment analysis in enhancing early warning system model f...
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
Auditboard EB SOX Playbook 2023 edition.
Rapid Prototyping: A lecture on prototyping techniques for interface design
Internet of Everything -Basic concepts details
Lung cancer patients survival prediction using outlier detection and optimize...
Comparative analysis of machine learning models for fake news detection in so...
Co-training pseudo-labeling for text classification with support vector machi...
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
future_of_ai_comprehensive_20250822032121.pptx
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Improvisation in detection of pomegranate leaf disease using transfer learni...
Custom Battery Pack Design Considerations for Performance and Safety
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
NewMind AI Weekly Chronicles – August ’25 Week IV
Module 1 Introduction to Web Programming .pptx
Ad

Enforce Consistency through Application Infrastructure