Slide 1

Slide 1 text

Laying it out: Onion Architecture Fanie Reynders Team Lead @FanieReynders

Slide 2

Slide 2 text

The centre of your application is not the database, it's the use cases of your application. Fanie Reynders @FanieReynders “ ”

Slide 3

Slide 3 text

Traditional Layered Architecture Infrastructure / DAL Core / BLL UI DB Utilities / Common / Shared nHibernate / LINQ to SQL ASP.NET Log4Net AutoMapper StructureMap

Slide 4

Slide 4 text

Problems with Traditional Architecture Very easy for developers to put increasing business logic in the UI layer Application is built on top of specific technology that is sure to change over time – counter productive Logic is scattered all over – difficult to locate & track Where should the code go? BLL? DAL? Utilities? Business Logic with extending tentacles Library Explosion – Easy to take a dependency

Slide 5

Slide 5 text

Different View: Traditional Architecture

Slide 6

Slide 6 text

Onion Architecture: Concept Overview

Slide 7

Slide 7 text

Onion Architecture: Concept Details

Slide 8

Slide 8 text

Inverted Dependencies Infrastructure / DAL Core / BLL UI DB Utilities / Common / Shared nHibernate / LINQ to SQL ASP.NET Log4Net AutoMapper StructureMap

Slide 9

Slide 9 text

Onion Architecture Infrastructure (DAL) Core (BLL) UI DB Dependency Resolution (Utilities) nHibernate / LINQ to SQL ASP.NET Log4Net StructureMap AutoMapper

Slide 10

Slide 10 text

Benefits of Onion Architecture True loosely coupled Limit re-write over time – Business Logic self contained Very portable Business Logic has no dependencies Architecture more sustainable over time Infrastructure free to use any data access or external service to accomplish task UI & Data Access smaller – deal directly with technology-related code Compiler enforces dependency boundaries

Slide 11

Slide 11 text

Example ProductsController Browser hits: /Products/List IProductRepository IUserSession HttpUserSession <> ProductRepository <> DB

Slide 12

Slide 12 text

Traditional Layered Architecture • Unique to business: Domain model, validation, business workflows • Defines contracts • CANNOT reference external libraries • NO technology specific code Core • Provide implementations for Core interfaces • Call web services, access database • CAN reference external libraries • ONLY contains technology specific code (non-business) Infrastructure • Wires up Core interfaces with Infrastructure implementations • Runs start-up / configuration / binding logic Dependency Resolution

Slide 13

Slide 13 text

Thank you