SlideShare a Scribd company logo
1 of 22
Download to read offline
Model View ViewModel
In medio stat virtus



Mauro Servienti
Microsoft MVP - Visual C#
Senior Software Architecht @ Gaia

http://milestone.topics.it/
mauro.servienti@gaia.is.it
Agenda
•   Preambolo...
•   Overview
•   Anatomia
•   Magagne :-)
Qualche cosa dobbiamo dircela...

M-V-VM: PREAMBOLO
Domandoni... :-)
• Che cosa ci deve far paura e perchè?
  – static...
  – new...
  – ServiceProvider.GetService<T>();


• Cosa è Dependency Injection?
• Cosa è Inversion of Control?
static




• Come lo testiamo?
  – E se mantiene uno stato?
• Se vogliamo cambiare il comportamento?
new




• Come lo testiamo?
• Se vogliamo cambiare il comportamento?
Dependency Injection




• lo testiamo :-) Mock to the max!
• Iniettiamo tutti i comportamenti che vogliamo
  – Può essere fatta via «ctor» o via «prop»
     • Optional vs Mandatory
Inversion of Control (1)
• Qualcuno un giorno sentenziò:
   – Luke: program to an interface... Mumble mumble...




• Ok, va bene, bello, figo, ma...: «new» is evil :-)
Inversion of Control (2)
• Deleghiamo il lavoro sporco! Tanto abbiamo
  capito cosa è DI;
Please, welcome «ServiceProvider»
• Activator.CreateInstance(): la preistoria di IoC
• Fx 1.0: IServiceProvider.GetService( Type svc );
• Perchè?
  – Lifetime!!!!
• Gli errori da non commettere:
  – DI diretta sul container;
  – «ServiceLocator» pattern... Blehaha...: è static;
• Il container è uno sconosciuto e tale deve
  restare :-)
Tutti ne parlano... Ma che cosa è?

M-V-VM: OVERVIEW
Please welcome M-V-VM




                                               presentation
                       View

                          DataBinding

                           Command




                                               engine
Il centro del        ViewModel          D.I.

   mondo!

                       Repository<T>

                       Model




                                               data
                              Adapter



                   Somewhere in
                      time...
Overview
• mediatore della comunicazione;
• Il designer non deve scrivere codice;
• sfrutta il potentissimo motore di DataBinding e di
  Commanding di Wpf;
• permette di «appiattire» un grafo, la UI è piatta!
• aggiunta di behavior ad un grafo:
   – e.g. Delete command su una row;
• aggiunta di informazioni ad un grafo:
   – e.g. proprietà calcolate, che non avrebbero senso sul
     dominio;
• semplificazione dello xaml perchè può ridurre
  drasticamente l'uso dei converter;
Smontiamolo :-)

M-V-VM: ANATOMIA
Anatomia
• È una banale classe che implementa
  INotifyPropertyChanged e basta! :-)
• Si potrebbe essere tentati di dipendere da
  DependencyObject
  – ma introduciamo una dipendendenza da tutto
    Wpf al solo scopo di avere la notifica simile a
    INotifyPropertyChanged
Demo

ITALIANI! FACCIAMOLO...
Anatomia: considerazioni
• View first o ViewModel first?
  – La blendability è importante;
  – Come comunicano View e ViewModel:
     • Uno per tutti: Intercettare la chiusura della View
• In ottica DI se il ViewModel ha delle
  dipendenze mandatory la View first ve la siete
  giocata;
• A questo punto DI ci porta verso IoC quindi è
  necessariamente ViewModel first;
Pregi & Difetti
• + Testabilità della logica della UI;
• + Sostituibilità della UI (stesso View Engine);
• + Elevata manutenibilità;

• - Aumento della complessità e mancanza di
  “controllori” (San csc.exe non aiuta...);
• - il data binding non risolve tutti gli scenari...
  dobbiamo sporcarci le manine... 
Bello... ma che sudate!

M-V-VM: MAGAGNE
Non è tutto oro quel che luccica
• Passate la vita a scrivere wrapper/dto;
• Il processo di validazione: IDataErrorInfo.
   – Ma come «triggheriamo»?
• Localizzazione: LocBAML... Ahahah che ridere;
• è produttivo? Dipende da vostro concetto di
  produttività:
   –   pessimo supporto dei designer visuali;
   –   struttura della solution obbliga alla rebuild;
   –   possiamo testare tutto, quasi;
   –   Elevatissima manutenibilità;
• è performante? Si, ma che importa? :-)
See it: live!

VEDIAMO UN PO’ DI SOLUZIONI...
Metto le cuffie :-)

DOMANDISSIME...?

More Related Content

Viewers also liked

Croce e delizia del lavoro remoto
Croce e delizia del lavoro remotoCroce e delizia del lavoro remoto
Croce e delizia del lavoro remotoMauro Servienti
 
Iter documentale per gli iscritti alla sezione E del RUI (collaborazione con ...
Iter documentale per gli iscritti alla sezione E del RUI (collaborazione con ...Iter documentale per gli iscritti alla sezione E del RUI (collaborazione con ...
Iter documentale per gli iscritti alla sezione E del RUI (collaborazione con ...Fabrizio Callarà
 
Single Sign On con IdentityServer
Single Sign On con IdentityServerSingle Sign On con IdentityServer
Single Sign On con IdentityServerMauro Servienti
 

Viewers also liked (6)

Ddd brutto sporco e cattivo
Ddd brutto sporco e cattivoDdd brutto sporco e cattivo
Ddd brutto sporco e cattivo
 
Croce e delizia del lavoro remoto
Croce e delizia del lavoro remotoCroce e delizia del lavoro remoto
Croce e delizia del lavoro remoto
 
Iter documentale per gli iscritti alla sezione E del RUI (collaborazione con ...
Iter documentale per gli iscritti alla sezione E del RUI (collaborazione con ...Iter documentale per gli iscritti alla sezione E del RUI (collaborazione con ...
Iter documentale per gli iscritti alla sezione E del RUI (collaborazione con ...
 
Single Sign On con IdentityServer
Single Sign On con IdentityServerSingle Sign On con IdentityServer
Single Sign On con IdentityServer
 
Introduzione WPF
Introduzione WPFIntroduzione WPF
Introduzione WPF
 
WPF MVVM Toolkit
WPF MVVM ToolkitWPF MVVM Toolkit
WPF MVVM Toolkit
 

Similar to m-v-vm @ dotNetMarche

Brokering over WCF @ dotNetMarche
Brokering over WCF @ dotNetMarcheBrokering over WCF @ dotNetMarche
Brokering over WCF @ dotNetMarcheMauro Servienti
 
Inversion of Control @ CD2008
Inversion of Control @ CD2008Inversion of Control @ CD2008
Inversion of Control @ CD2008Mauro Servienti
 
Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010Mauro Servienti
 
Industrial Iot - IotSaturday
Industrial Iot - IotSaturday Industrial Iot - IotSaturday
Industrial Iot - IotSaturday Riccardo Zamana
 
Il pattern mvvm come strutturare al meglio il vostro progetto
Il pattern mvvm come strutturare al meglio il vostro progettoIl pattern mvvm come strutturare al meglio il vostro progetto
Il pattern mvvm come strutturare al meglio il vostro progettoMicrosoft Mobile Developer
 
Doaw2020 - Dalla produzione alla QA, provisioning su SQL Server
Doaw2020 - Dalla produzione alla QA, provisioning su SQL ServerDoaw2020 - Dalla produzione alla QA, provisioning su SQL Server
Doaw2020 - Dalla produzione alla QA, provisioning su SQL ServerAlessandro Alpi
 
Fe04 angular js-101
Fe04   angular js-101Fe04   angular js-101
Fe04 angular js-101DotNetCampus
 
ASP.NET MVC: Andare oltre il 100% (Web@work)
ASP.NET MVC: Andare oltre il 100% (Web@work)ASP.NET MVC: Andare oltre il 100% (Web@work)
ASP.NET MVC: Andare oltre il 100% (Web@work)Giorgio Di Nardo
 
Model View Controller - Semplificare Il Codice E Minimizzare I Tempi
Model View Controller - Semplificare Il Codice E Minimizzare I TempiModel View Controller - Semplificare Il Codice E Minimizzare I Tempi
Model View Controller - Semplificare Il Codice E Minimizzare I TempiMarco Parenzan
 
Webinar: "Il database: l’equipaggiamento su cui fare affidamento"
Webinar: "Il database: l’equipaggiamento su cui fare affidamento"Webinar: "Il database: l’equipaggiamento su cui fare affidamento"
Webinar: "Il database: l’equipaggiamento su cui fare affidamento"Emerasoft, solutions to collaborate
 
Be01 web devclientvsserver
Be01   web devclientvsserverBe01   web devclientvsserver
Be01 web devclientvsserverDotNetCampus
 
Meetup ASP.NET Core Angular
Meetup ASP.NET Core AngularMeetup ASP.NET Core Angular
Meetup ASP.NET Core Angulardotnetcode
 
Entity Framework 7, Back To The Future!
Entity Framework 7, Back To The Future!Entity Framework 7, Back To The Future!
Entity Framework 7, Back To The Future!Michael Denny
 
Custom vision on edge device
Custom vision on edge deviceCustom vision on edge device
Custom vision on edge deviceAlessio Biasiutti
 
IoT Saturday 2019 - Custom Vision on Edge device
IoT Saturday 2019 - Custom Vision on Edge deviceIoT Saturday 2019 - Custom Vision on Edge device
IoT Saturday 2019 - Custom Vision on Edge deviceAlessio Biasiutti
 
Azure IoT Central per lo SCADA engineer
Azure IoT Central per lo SCADA engineerAzure IoT Central per lo SCADA engineer
Azure IoT Central per lo SCADA engineerMarco Parenzan
 

Similar to m-v-vm @ dotNetMarche (20)

m-v-vm @ UgiAlt.Net
m-v-vm @ UgiAlt.Netm-v-vm @ UgiAlt.Net
m-v-vm @ UgiAlt.Net
 
Brokering over WCF @ dotNetMarche
Brokering over WCF @ dotNetMarcheBrokering over WCF @ dotNetMarche
Brokering over WCF @ dotNetMarche
 
Inversion of Control @ CD2008
Inversion of Control @ CD2008Inversion of Control @ CD2008
Inversion of Control @ CD2008
 
UI Composition
UI CompositionUI Composition
UI Composition
 
Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010
 
Industrial Iot - IotSaturday
Industrial Iot - IotSaturday Industrial Iot - IotSaturday
Industrial Iot - IotSaturday
 
Il pattern mvvm come strutturare al meglio il vostro progetto
Il pattern mvvm come strutturare al meglio il vostro progettoIl pattern mvvm come strutturare al meglio il vostro progetto
Il pattern mvvm come strutturare al meglio il vostro progetto
 
Doaw2020 - Dalla produzione alla QA, provisioning su SQL Server
Doaw2020 - Dalla produzione alla QA, provisioning su SQL ServerDoaw2020 - Dalla produzione alla QA, provisioning su SQL Server
Doaw2020 - Dalla produzione alla QA, provisioning su SQL Server
 
OrientDB & Big Data
OrientDB & Big DataOrientDB & Big Data
OrientDB & Big Data
 
Fe04 angular js-101
Fe04   angular js-101Fe04   angular js-101
Fe04 angular js-101
 
ASP.NET MVC: Andare oltre il 100% (Web@work)
ASP.NET MVC: Andare oltre il 100% (Web@work)ASP.NET MVC: Andare oltre il 100% (Web@work)
ASP.NET MVC: Andare oltre il 100% (Web@work)
 
Model View Controller - Semplificare Il Codice E Minimizzare I Tempi
Model View Controller - Semplificare Il Codice E Minimizzare I TempiModel View Controller - Semplificare Il Codice E Minimizzare I Tempi
Model View Controller - Semplificare Il Codice E Minimizzare I Tempi
 
Webinar: "Il database: l’equipaggiamento su cui fare affidamento"
Webinar: "Il database: l’equipaggiamento su cui fare affidamento"Webinar: "Il database: l’equipaggiamento su cui fare affidamento"
Webinar: "Il database: l’equipaggiamento su cui fare affidamento"
 
Be01 web devclientvsserver
Be01   web devclientvsserverBe01   web devclientvsserver
Be01 web devclientvsserver
 
Meetup ASP.NET Core Angular
Meetup ASP.NET Core AngularMeetup ASP.NET Core Angular
Meetup ASP.NET Core Angular
 
Entity Framework 7, Back To The Future!
Entity Framework 7, Back To The Future!Entity Framework 7, Back To The Future!
Entity Framework 7, Back To The Future!
 
Custom vision on edge device
Custom vision on edge deviceCustom vision on edge device
Custom vision on edge device
 
IoT Saturday 2019 - Custom Vision on Edge device
IoT Saturday 2019 - Custom Vision on Edge deviceIoT Saturday 2019 - Custom Vision on Edge device
IoT Saturday 2019 - Custom Vision on Edge device
 
3DD 1e Reconfig
3DD 1e Reconfig3DD 1e Reconfig
3DD 1e Reconfig
 
Azure IoT Central per lo SCADA engineer
Azure IoT Central per lo SCADA engineerAzure IoT Central per lo SCADA engineer
Azure IoT Central per lo SCADA engineer
 

More from Mauro Servienti

Welcome to the (state) machine @ ExploreDDD 2019
Welcome to the (state) machine @ ExploreDDD 2019Welcome to the (state) machine @ ExploreDDD 2019
Welcome to the (state) machine @ ExploreDDD 2019Mauro Servienti
 
Designing a ui for microservices @ .NET Day Switzerland 2019
Designing a ui for microservices @ .NET Day Switzerland 2019Designing a ui for microservices @ .NET Day Switzerland 2019
Designing a ui for microservices @ .NET Day Switzerland 2019Mauro Servienti
 
Welcome to the (state) machine @ Xe One Day Enterprise Applications
Welcome to the (state) machine @ Xe One Day Enterprise ApplicationsWelcome to the (state) machine @ Xe One Day Enterprise Applications
Welcome to the (state) machine @ Xe One Day Enterprise ApplicationsMauro Servienti
 
All our aggregates are wrong @ NDC Copenhagen 2019
All our aggregates are wrong @ NDC Copenhagen 2019All our aggregates are wrong @ NDC Copenhagen 2019
All our aggregates are wrong @ NDC Copenhagen 2019Mauro Servienti
 
Be like water, my friend @ Agile for Innovation 2019
Be like water, my friend @ Agile for Innovation 2019Be like water, my friend @ Agile for Innovation 2019
Be like water, my friend @ Agile for Innovation 2019Mauro Servienti
 
Microservices architecture is it the right choice to design long-living syste...
Microservices architecture is it the right choice to design long-living syste...Microservices architecture is it the right choice to design long-living syste...
Microservices architecture is it the right choice to design long-living syste...Mauro Servienti
 
Titles, abstracts, and bio matter... oh my! @ Global Diversity CFP Day 2019
Titles, abstracts, and bio matter... oh my! @ Global Diversity CFP Day 2019Titles, abstracts, and bio matter... oh my! @ Global Diversity CFP Day 2019
Titles, abstracts, and bio matter... oh my! @ Global Diversity CFP Day 2019Mauro Servienti
 
Living organizations, particular software @ do IT Better Parma
Living organizations, particular software @ do IT Better ParmaLiving organizations, particular software @ do IT Better Parma
Living organizations, particular software @ do IT Better ParmaMauro Servienti
 
Welcome to the (state) machine @ Crafted Software
Welcome to the (state) machine @ Crafted SoftwareWelcome to the (state) machine @ Crafted Software
Welcome to the (state) machine @ Crafted SoftwareMauro Servienti
 
PO is dead, long live the PO - Italian Agile Day 2018
PO is dead, long live the PO - Italian Agile Day 2018PO is dead, long live the PO - Italian Agile Day 2018
PO is dead, long live the PO - Italian Agile Day 2018Mauro Servienti
 
Design a UI for your Microservices @ Do IT Better
Design a UI for your Microservices @ Do IT BetterDesign a UI for your Microservices @ Do IT Better
Design a UI for your Microservices @ Do IT BetterMauro Servienti
 
Microservices and pineapple on pizza what do they have in common - dos and ...
Microservices and pineapple on pizza   what do they have in common - dos and ...Microservices and pineapple on pizza   what do they have in common - dos and ...
Microservices and pineapple on pizza what do they have in common - dos and ...Mauro Servienti
 
All our aggregates are wrong (ExploreDDD 2018)
All our aggregates are wrong (ExploreDDD 2018)All our aggregates are wrong (ExploreDDD 2018)
All our aggregates are wrong (ExploreDDD 2018)Mauro Servienti
 
Designing a ui for microservices
Designing a ui for microservicesDesigning a ui for microservices
Designing a ui for microservicesMauro Servienti
 
Po is dead, long live the po
Po is dead, long live the poPo is dead, long live the po
Po is dead, long live the poMauro Servienti
 
Shipping code is not the problem, deciding what to ship it is!
Shipping code is not the problem, deciding what to ship it is!Shipping code is not the problem, deciding what to ship it is!
Shipping code is not the problem, deciding what to ship it is!Mauro Servienti
 
GraphQL - Where are you from? Where are you going?
GraphQL - Where are you from? Where are you going?GraphQL - Where are you from? Where are you going?
GraphQL - Where are you from? Where are you going?Mauro Servienti
 
Dall'idea al deploy un lungo viaggio che passa per git flow e semver
Dall'idea al deploy   un lungo viaggio che passa per git flow e semverDall'idea al deploy   un lungo viaggio che passa per git flow e semver
Dall'idea al deploy un lungo viaggio che passa per git flow e semverMauro Servienti
 
Progettare una UI per i Microservices
Progettare una UI per i MicroservicesProgettare una UI per i Microservices
Progettare una UI per i MicroservicesMauro Servienti
 
The road to a Service Oriented Architecture is paved with messages
The road to a Service Oriented Architecture is paved with messagesThe road to a Service Oriented Architecture is paved with messages
The road to a Service Oriented Architecture is paved with messagesMauro Servienti
 

More from Mauro Servienti (20)

Welcome to the (state) machine @ ExploreDDD 2019
Welcome to the (state) machine @ ExploreDDD 2019Welcome to the (state) machine @ ExploreDDD 2019
Welcome to the (state) machine @ ExploreDDD 2019
 
Designing a ui for microservices @ .NET Day Switzerland 2019
Designing a ui for microservices @ .NET Day Switzerland 2019Designing a ui for microservices @ .NET Day Switzerland 2019
Designing a ui for microservices @ .NET Day Switzerland 2019
 
Welcome to the (state) machine @ Xe One Day Enterprise Applications
Welcome to the (state) machine @ Xe One Day Enterprise ApplicationsWelcome to the (state) machine @ Xe One Day Enterprise Applications
Welcome to the (state) machine @ Xe One Day Enterprise Applications
 
All our aggregates are wrong @ NDC Copenhagen 2019
All our aggregates are wrong @ NDC Copenhagen 2019All our aggregates are wrong @ NDC Copenhagen 2019
All our aggregates are wrong @ NDC Copenhagen 2019
 
Be like water, my friend @ Agile for Innovation 2019
Be like water, my friend @ Agile for Innovation 2019Be like water, my friend @ Agile for Innovation 2019
Be like water, my friend @ Agile for Innovation 2019
 
Microservices architecture is it the right choice to design long-living syste...
Microservices architecture is it the right choice to design long-living syste...Microservices architecture is it the right choice to design long-living syste...
Microservices architecture is it the right choice to design long-living syste...
 
Titles, abstracts, and bio matter... oh my! @ Global Diversity CFP Day 2019
Titles, abstracts, and bio matter... oh my! @ Global Diversity CFP Day 2019Titles, abstracts, and bio matter... oh my! @ Global Diversity CFP Day 2019
Titles, abstracts, and bio matter... oh my! @ Global Diversity CFP Day 2019
 
Living organizations, particular software @ do IT Better Parma
Living organizations, particular software @ do IT Better ParmaLiving organizations, particular software @ do IT Better Parma
Living organizations, particular software @ do IT Better Parma
 
Welcome to the (state) machine @ Crafted Software
Welcome to the (state) machine @ Crafted SoftwareWelcome to the (state) machine @ Crafted Software
Welcome to the (state) machine @ Crafted Software
 
PO is dead, long live the PO - Italian Agile Day 2018
PO is dead, long live the PO - Italian Agile Day 2018PO is dead, long live the PO - Italian Agile Day 2018
PO is dead, long live the PO - Italian Agile Day 2018
 
Design a UI for your Microservices @ Do IT Better
Design a UI for your Microservices @ Do IT BetterDesign a UI for your Microservices @ Do IT Better
Design a UI for your Microservices @ Do IT Better
 
Microservices and pineapple on pizza what do they have in common - dos and ...
Microservices and pineapple on pizza   what do they have in common - dos and ...Microservices and pineapple on pizza   what do they have in common - dos and ...
Microservices and pineapple on pizza what do they have in common - dos and ...
 
All our aggregates are wrong (ExploreDDD 2018)
All our aggregates are wrong (ExploreDDD 2018)All our aggregates are wrong (ExploreDDD 2018)
All our aggregates are wrong (ExploreDDD 2018)
 
Designing a ui for microservices
Designing a ui for microservicesDesigning a ui for microservices
Designing a ui for microservices
 
Po is dead, long live the po
Po is dead, long live the poPo is dead, long live the po
Po is dead, long live the po
 
Shipping code is not the problem, deciding what to ship it is!
Shipping code is not the problem, deciding what to ship it is!Shipping code is not the problem, deciding what to ship it is!
Shipping code is not the problem, deciding what to ship it is!
 
GraphQL - Where are you from? Where are you going?
GraphQL - Where are you from? Where are you going?GraphQL - Where are you from? Where are you going?
GraphQL - Where are you from? Where are you going?
 
Dall'idea al deploy un lungo viaggio che passa per git flow e semver
Dall'idea al deploy   un lungo viaggio che passa per git flow e semverDall'idea al deploy   un lungo viaggio che passa per git flow e semver
Dall'idea al deploy un lungo viaggio che passa per git flow e semver
 
Progettare una UI per i Microservices
Progettare una UI per i MicroservicesProgettare una UI per i Microservices
Progettare una UI per i Microservices
 
The road to a Service Oriented Architecture is paved with messages
The road to a Service Oriented Architecture is paved with messagesThe road to a Service Oriented Architecture is paved with messages
The road to a Service Oriented Architecture is paved with messages
 

m-v-vm @ dotNetMarche

  • 1. Model View ViewModel In medio stat virtus Mauro Servienti Microsoft MVP - Visual C# Senior Software Architecht @ Gaia http://milestone.topics.it/ mauro.servienti@gaia.is.it
  • 2. Agenda • Preambolo... • Overview • Anatomia • Magagne :-)
  • 3. Qualche cosa dobbiamo dircela... M-V-VM: PREAMBOLO
  • 4. Domandoni... :-) • Che cosa ci deve far paura e perchè? – static... – new... – ServiceProvider.GetService<T>(); • Cosa è Dependency Injection? • Cosa è Inversion of Control?
  • 5. static • Come lo testiamo? – E se mantiene uno stato? • Se vogliamo cambiare il comportamento?
  • 6. new • Come lo testiamo? • Se vogliamo cambiare il comportamento?
  • 7. Dependency Injection • lo testiamo :-) Mock to the max! • Iniettiamo tutti i comportamenti che vogliamo – Può essere fatta via «ctor» o via «prop» • Optional vs Mandatory
  • 8. Inversion of Control (1) • Qualcuno un giorno sentenziò: – Luke: program to an interface... Mumble mumble... • Ok, va bene, bello, figo, ma...: «new» is evil :-)
  • 9. Inversion of Control (2) • Deleghiamo il lavoro sporco! Tanto abbiamo capito cosa è DI;
  • 10. Please, welcome «ServiceProvider» • Activator.CreateInstance(): la preistoria di IoC • Fx 1.0: IServiceProvider.GetService( Type svc ); • Perchè? – Lifetime!!!! • Gli errori da non commettere: – DI diretta sul container; – «ServiceLocator» pattern... Blehaha...: è static; • Il container è uno sconosciuto e tale deve restare :-)
  • 11. Tutti ne parlano... Ma che cosa è? M-V-VM: OVERVIEW
  • 12. Please welcome M-V-VM presentation View DataBinding Command engine Il centro del ViewModel D.I. mondo! Repository<T> Model data Adapter Somewhere in time...
  • 13. Overview • mediatore della comunicazione; • Il designer non deve scrivere codice; • sfrutta il potentissimo motore di DataBinding e di Commanding di Wpf; • permette di «appiattire» un grafo, la UI è piatta! • aggiunta di behavior ad un grafo: – e.g. Delete command su una row; • aggiunta di informazioni ad un grafo: – e.g. proprietà calcolate, che non avrebbero senso sul dominio; • semplificazione dello xaml perchè può ridurre drasticamente l'uso dei converter;
  • 15. Anatomia • È una banale classe che implementa INotifyPropertyChanged e basta! :-) • Si potrebbe essere tentati di dipendere da DependencyObject – ma introduciamo una dipendendenza da tutto Wpf al solo scopo di avere la notifica simile a INotifyPropertyChanged
  • 17. Anatomia: considerazioni • View first o ViewModel first? – La blendability è importante; – Come comunicano View e ViewModel: • Uno per tutti: Intercettare la chiusura della View • In ottica DI se il ViewModel ha delle dipendenze mandatory la View first ve la siete giocata; • A questo punto DI ci porta verso IoC quindi è necessariamente ViewModel first;
  • 18. Pregi & Difetti • + Testabilità della logica della UI; • + Sostituibilità della UI (stesso View Engine); • + Elevata manutenibilità; • - Aumento della complessità e mancanza di “controllori” (San csc.exe non aiuta...); • - il data binding non risolve tutti gli scenari... dobbiamo sporcarci le manine... 
  • 19. Bello... ma che sudate! M-V-VM: MAGAGNE
  • 20. Non è tutto oro quel che luccica • Passate la vita a scrivere wrapper/dto; • Il processo di validazione: IDataErrorInfo. – Ma come «triggheriamo»? • Localizzazione: LocBAML... Ahahah che ridere; • è produttivo? Dipende da vostro concetto di produttività: – pessimo supporto dei designer visuali; – struttura della solution obbliga alla rebuild; – possiamo testare tutto, quasi; – Elevatissima manutenibilità; • è performante? Si, ma che importa? :-)
  • 21. See it: live! VEDIAMO UN PO’ DI SOLUZIONI...
  • 22. Metto le cuffie :-) DOMANDISSIME...?