Esempi di IoC e DI (Alessandro Giorgetti)

14
IoC/DI in Action Modularization – Service Locator – Abstract Factories … and SL 4 Eng. Giorgetti Alessandro Software Artisan SID s.r.l.

description

Tramite esempi di codice vedremo come poter applicare i principi della DI e dell'IoC appena introdotti, e come poter refattorizzare delle applicazioni già esistenti per andare in questa direzione, in modo da usufruire dei vantaggi indicati. Parleremo inoltre di alcune best practice o situazioni da evitare per non andare incontro a nuovi problemi creati dall'adozione di queste tecniche.

Transcript of Esempi di IoC e DI (Alessandro Giorgetti)

Page 1: Esempi di IoC e DI (Alessandro Giorgetti)

IoC/DI in ActionModularization – Service Locator – Abstract Factories … and SL 4

Eng. Giorgetti AlessandroSoftware ArtisanSID s.r.l.

Page 2: Esempi di IoC e DI (Alessandro Giorgetti)

Two words about me

Graduated EngineerOwner/co-founder of SID s.r.l.Blog: http://www.primordialcode.comEmail: [email protected]: @A_Giorgetti

Giorgetti Alessandro

Page 3: Esempi di IoC e DI (Alessandro Giorgetti)

Engineering an Application

To be able to use an IoC/DI framework effectively you need to structure your application the right way!Your first problem is an Architectural problem:

How to partition an application?How to structure each module?What are the interactions?Dependencies?…

Page 4: Esempi di IoC e DI (Alessandro Giorgetti)

Engineering an Application

Only When you’ve answered those questions, you can think of how to implement the solution!

Only at this stage you can start thinking of which ‘tool’ to use and which ‘best practice’ you can follow to solve your problems!

Page 5: Esempi di IoC e DI (Alessandro Giorgetti)

Application Architecture

When you think of an application architecture, usually this is the first thing it come into your mind:

DAL

Business Logic

User Interface

Secu

rty

Logg

ing

InfrastructureRIGHT!….but also WRONG!

Page 6: Esempi di IoC e DI (Alessandro Giorgetti)

Application Architecture

When using a IoC/DI container your application sounds more like this:

Security ServiceIService1Module1

Logging ServiceIService2Module2

Infrastructure

Shell

Application Framework

IService3 Messaging Service

Page 7: Esempi di IoC e DI (Alessandro Giorgetti)

Application Architecture

When implementing a module/service

Module1

Module2

Infrastructure

Shell

Application Framework

DAL

Business Logic

User Interface

Secu

rty

Logg

ing

Infrastructure

Page 8: Esempi di IoC e DI (Alessandro Giorgetti)

Hints when building an Architecture based on IoC

Keep things simple!Use a top-down approach while defining and designing the applicationBreak the application in modules / features and decouple the more you can: reusability, easy implementationThink using ‘interfaces’ (do not try to implement anything at this stage)…but avoid over-engineering

Page 9: Esempi di IoC e DI (Alessandro Giorgetti)

Problems – Architectural level

Design Interfaces

Component configuration, creation, lifecycle IoC/DI/ServiceLocator, etc…

Managing interactions data storage, shared data, message brokering, etc…

Page 10: Esempi di IoC e DI (Alessandro Giorgetti)

Problems – Module/Feature level

You have plenty of ‘tools’ and ‘patterns’ that helps you implementing your solution:

• Layered applications

• Implementation patterns (MVC, MVVM, …)

• Reuse services

Page 11: Esempi di IoC e DI (Alessandro Giorgetti)

ServiceLocator – Abstract Factoriesmetacode

Eng. Giorgetti Alessandro

demo

Page 12: Esempi di IoC e DI (Alessandro Giorgetti)

MusicStore (SL 4 version)an example of those techniques in action

Eng. Giorgetti Alessandro

demo

Page 13: Esempi di IoC e DI (Alessandro Giorgetti)

MusicStore (SL 4 version)some indepths

Inspired by this workshop I’ve started a series of articles on my blog you can check to dig into some of the arguments I proposed here:

Silverlight, MVVM … and IoChttp://www.primordialcode.com/blog/post/silverlight-mvvm-ioc-part-1http://www.primordialcode.com/blog/post/silverlight-mvvm-ioc-part-2

Silverlight Navigation Framework … and IoChttp://www.primordialcode.com/blog/post/silverlight-navigation-framework-resolve-pages-ioc-container

More to come…

Page 14: Esempi di IoC e DI (Alessandro Giorgetti)

Eng. Giorgetti Alessandro

Questions ? (and maybe … answers)