Introduzione ai framework ioc

1,279 views

Published on

Seconda sessione del 14° workshop dotnetmarche.org

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,279
On SlideShare
0
From Embeds
0
Number of Embeds
45
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Introduzione ai framework ioc

  1. 1. Introduzione ai framework per IoC / DI e AOP<br />14° Workshop – DotNetMarche :: Castelfidardo, 16 Aprile 2010<br />
  2. 2. andreabalducci<br />Riferimenti<br />Andrea Balducci<br />http://www.ienumerable.it<br />mtb.snowboard @ gmail.com<br />
  3. 3. Framework<br />
  4. 4. Unity<br />“The Unity Application Block (Unity) is a lightweight extensible dependency injection container with support for constructor, property, and method call injection.”<br />http://unity.codeplex.com/<br />
  5. 5. Definiamo un contratto<br />public interface IOperazioneMatematica<br />{<br />int Esegui(int a, int b);<br />}<br />
  6. 6. Implementazione<br />public classOperazioneSomma : IOperazioneMatematica<br />{<br /> public int Esegui(int a, int b)<br /> {<br />return a + b;<br /> }<br />}<br />
  7. 7. Configurazione del container<br />// Creazione container<br />IUnityContainer container = newUnityContainer();<br />// Registrazione componenti<br />container.RegisterType<<br />IOperazioneMatematica, // contratto<br />OperazioneSomma // implementazione<br />>();<br />
  8. 8. Utilizzo del container<br />// Richiesta del servizio di calcolo<br />var operazione = <br />container.Resolve<IOperazioneMatematica>();<br />// Utilizzo del servizio<br />int risultato = operazione.Esegui(1, 2);<br />
  9. 9. Injection<br />[InjectionConstructor]<br />Per marcare un costruttore da utilizzare esplicitamente. In assenza viene usato il costruttore con il maggior numero di parametri. <br />[Dependency]<br />Marca il setter della property<br />[InjectionMethod]<br />Marca un metodo di inizializzazione<br />
  10. 10. {demo}<br />
  11. 11. Castle Windsor<br />“The Castle MicroKernel is an inversion of control container that was designed towards extensibility. It combines facilities to grow orthogonally.”<br />Castle Windsor aggregates the MicroKernel and exposes a powerful configuration support. It is suitable for common enterprise application needs. It is able to register facilities and components based on the configuration and adds support for interceptors<br />http://www.castleproject.org/container/index.html<br />
  12. 12. Windsor - ComponentLifecycle<br />http://www.castleproject.org/container/documentation/v21/usersguide/lifestyles.html<br />
  13. 13. {demo}<br />
  14. 14. Castle - Facilities<br />http://www.castleproject.org/container/facilities/trunk/index.html<br />
  15. 15. {demo}<br />
  16. 16. andreabalducci<br />{grazie}<br />

×