SlideShare a Scribd company logo
ASP.NET MVC:
Andare oltre il 100%
      Giorgio Di Nardo
        Proge-Software s.r.l.
giorgio.dinardo@domusdotnet.org
              @akelitz
 http://blogs.ugidotnet.org/akelitz


 Web@Work
Web@Work
Grazie agli sponsor
Web@Work
Agenda


•   NuGet
•   Url localization
•   Dependency Resolver
•   Unit testing
Web@Work
NuGet

  Aggiungere un riferimento   Aggiungere un riferimento
       senza NuGet                  con NuGet

Trovarlo

 Scaricarlo

  Estrarlo
                              Aggiungere
                              pacchetto
    Referenziarlo

      Configurarlo
Web@Work
NuGet


• Un Package Manager per .NET e Visual
  Studio
• Installabile tramite Extension Manager
• Utilizzabile tramite:
 •   GUI
 •   Console PowerShell
 •   Tool a riga di comando
• Supporta sorgenti multiple (pubbliche e
  private)
Ciclo di vita di una richiesta            Web@Work
con ASP.NET MVC

                Model
   Request                       Action    Response
                Binder




    URL                          Action
               Controller                   View
   Routing                       Filter




    HTTP       Controller        Action      View
   Handler      Factory          Result     Engine
Web@Work
Localizzazione


• Processo attraverso il quale è possibile
  fornire il contenuto della nostra
  applicazione in diverse lingue senza
  dover riscrivere tutto
• Tipicamente ottenuto per mezzo di file di
  risorsa tradotti nelle varie lingue da
  supportare
• Disponibile out-of-the-box con ASP.NET
Web@Work




demo
Web@Work
Singly Registered Services

• IControllerActivator
  •   DefaultControllerActivator
• IControllerFactory
  (ControllerBuilder.Current.SetControllerFact
  ory)
  •   DefaultControllerFactory
• IViewPageActivator
  •   DefaultViewPageActivator
• ModelMetadataProvider
  (ModelMetadataProviders.Current)
  •   DataAnnotationsModelMetadataProvider
Multiply Registered Services           Web@Work
(cooperative)

• IFilterProvider (FilterProviders.Providers)
  • FilterAttributeFilterProvider
  • GlobalFilterCollection
  • ControllerInstanceFilterProvider
• ModelValidatorProvider
  (ModelValidatorProviders.Providers)
  • DataAnnotationsModelValidatorProvider
  • DataErrorInfoModelValidatorProvider
  • ClientDataTypeModelValidatorProvider
Multiply Registered Services                      Web@Work
(competitive)

•       IModelBinderProvider
        (ModelBinderProviders.BinderProviders)
    •    DefaultControllerFactory
•       IViewEngine (ViewEngines.Engines)
    •    WebFormViewEngine
    •    RazorViewEngine
•       ValueProviderFactory
        (ValueProviderFactories.Factories)
    •    ChildActionValueProviderFactory
    •    FormValueProviderFactory
    •    JsonValueProviderFactory
    •    RouteDataValueProviderFactory
    •    QueryStringValueProviderFactory
    •    HttpFileCollectionValueProviderFactory
Web@Work
Dependency Resolver

• Consente di risolvere i problemi di
  dipendenza
• Concretizzazione del pattern astratto
  Inversion-of-Control (IoC)




• Permette di incapsulare facilmente uno IoC
  Container
• Molte implementazioni disponibili su NuGet
Web@Work
Dipendenze e IoC


• Il componente A da passivo (subisce la
  scelta di B di usare C)...
      Componente   Componente     Servizio
          A            B             C

• ...diventa attivo (impone a B di usare D
  per svolgere un azione di tipo IC)
      Componente     Servizio   Componente
          A           D : IC        B
Web@Work
Inversion of Control
Web@Work
Inversion of Control
Web@Work
Service Locator


• Il pattern Service Locator implementa
  l’astrazione di IoC definendo un
  componente esterno responsabile della
  risoluzione delle dipendenze
• Un Service Locator può essere:
  • Specifico: consente la risoluzione strongly
    typed di interfacce ben definite
  • Generico: fornisce un approccio generico per
    la risoluzione di qualunque tipo di dipendenza
Web@Work
Service Locator specifici
Web@Work
SL specifici: pregi e difetti


• È facile da capire e utilizzare
• Consente di personalizzare la creazione
  degli oggetti usando parametri
• È limitato alla creazione degli oggetti
  previsti in fase di design
• Rischia di trasformare la sua
  manutenzione in un incubo
Web@Work
Service Locator generici
Web@Work
SL generici: pregi e difetti


• Risolve ogni tipo di dipendenza anche
  senza conoscere il tipo di oggetto
  richiesto
• Riduce i costi di manutenzione, non
  richiedendo la modifica dell’interfaccia
• Non fornisce informazioni qualitative sui
  servizi che eroga (o che non eroga)
• Non consente di personalizzare la
  creazione degli oggetti restituiti
Web@Work
Dependency Injection

• Implementazione di IoC basata sulla
  realizzazione dei componenti in modo tale
  da consentire un’esplicità indicazione
  delle dipendenze dall’esterno
• Rispetto a SL consente una trasparenza
  del codice nettamente maggiore
• Può essere declinata in due varianti:
  • Constructor Injection
  • Property Injection
Web@Work
DI: Constructor Injection


• Forma più comune di Dependency
  Injection
• Il costruttore del componente specifica
  esplicitamente tutte le sue dipendenze
• Il componente non deve conoscere i
  dettagli di funzionamento del Service
  Locator
• L’utilizzo del componente è chiaro con un
  semplice sguardo al costruttore
Web@Work
DI: Property Injection

• Forma meno comune di Dependency
  Injection
• Le dipendenze possono essere iniettate
  impostando proprietà apposite
• È meno chiaro che prima di utilizzare un
  metodo del componente bisogna settare una
  proprietà
• Consente di specificare dipendenze
  opzionali
• Unica scelta se non si può gestire la
  chiamata al costruttore
Web@Work
Dependency Injection Containers

• Entrambi i metodi dicono «cosa» fare ma
  non «come» farlo: la risposta è nei DI
  Container
• Sono librerie che agiscono come Factory
  dei componenti analizzando
  automaticamente le dipendenze
• Simili nell’aspetto esterno ai SL si
  prendono però carico anche della
  creazione dell’oggetto da restituire
Web@Work




demo
Web@Work
Testing, Unit testing e TDD


• Parte dello sviluppo software che si
  occupa della verifica delle corrispondenza
  tra il funzionamento del codice e i requisiti
• Unit testing, integration
  testing, performance testing, scalability
  testing
• Consente di migliorare la qualità del
  proprio codice, ridurre il peso della
  manutenzione ma anche (TDD)
  migliorarne il design
Web@Work
Pilastri dello Unit testing


• Testare piccoli frammenti di codice
  («unit»), tipicamente metodi
• Testare in maniera isolata rispetto al resto
  dell’applicazione
• Testare i soli endpoint pubblici
• Ottenere il risultato positivo/negativo dei
  test in maniera automatizzata
Web@Work
Test Driven Design


• Utilizzare lo Unit testing per guidare lo
  sviluppo della propria applicazione
• Scrivere il codice strettamente necessario
  a passare i test
• Red/Green cycle
• Utilizzabile sia per i nuovi sviluppi che per
  il bug fixing
• Attenzione al refactoring!
Web@Work
Arrange, Act, Assert


• Arrange: predisporre l’ambiente per il test
• Act: effettuare la chiamata al codice
  oggetto del test
• Assert: verificare che ciò che ci si
  aspettava si è verificato (e ciò che non ci
  si aspettava non si è verificato)
• Verificare un comportamente alla volta
  (single assertion rule)
Web@Work




demo
Web@Work
Grazie agli sponsor

More Related Content

What's hot

Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Andrea Dottor
 
DotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql ServerDotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql Server
Alessandro Alpi
 
Sviluppo Web con React e Delphi - Seminario Delphi Day 2016, Piacenza
Sviluppo Web con React e Delphi - Seminario Delphi Day 2016, PiacenzaSviluppo Web con React e Delphi - Seminario Delphi Day 2016, Piacenza
Sviluppo Web con React e Delphi - Seminario Delphi Day 2016, Piacenza
Marco Breveglieri
 
Alla scoperta di gRPC
Alla scoperta di gRPCAlla scoperta di gRPC
Alla scoperta di gRPC
Andrea Dottor
 
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
Alessandro Alpi
 
Blazor per uno sviluppatore Web Form
Blazor per uno sviluppatore Web FormBlazor per uno sviluppatore Web Form
Blazor per uno sviluppatore Web Form
Andrea Dottor
 
Angularjs
AngularjsAngularjs
Angularjs
Francesco Portus
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
Pietro Libro
 
AntiPatterns: i vizi del programmatore
AntiPatterns: i vizi del programmatoreAntiPatterns: i vizi del programmatore
AntiPatterns: i vizi del programmatore
Manuel Scapolan
 
Delphi & Dintorni Webinar - Diventa un mago del Testing
Delphi & Dintorni Webinar - Diventa un mago del TestingDelphi & Dintorni Webinar - Diventa un mago del Testing
Delphi & Dintorni Webinar - Diventa un mago del Testing
Marco Breveglieri
 
Dot netcampus2015 green-template
Dot netcampus2015 green-templateDot netcampus2015 green-template
Dot netcampus2015 green-templateDotNetCampus
 
ASP.NET MVC 6 - uno sguardo al futuro
ASP.NET MVC 6 - uno sguardo al futuroASP.NET MVC 6 - uno sguardo al futuro
ASP.NET MVC 6 - uno sguardo al futuro
Andrea Dottor
 
Cosa c'è di nuovo in asp.net core 2 0
Cosa c'è di nuovo in asp.net core 2 0Cosa c'è di nuovo in asp.net core 2 0
Cosa c'è di nuovo in asp.net core 2 0
Andrea Dottor
 
ASP.NET MVC: sfruttare la piattaforma al 100%
ASP.NET MVC: sfruttare la piattaforma al 100%ASP.NET MVC: sfruttare la piattaforma al 100%
ASP.NET MVC: sfruttare la piattaforma al 100%
DomusDotNet
 
Dependency injection questa sconosciuta
Dependency injection questa sconosciutaDependency injection questa sconosciuta
Dependency injection questa sconosciuta
Andrea Dottor
 
Azure dev ops meetup one
Azure dev ops meetup oneAzure dev ops meetup one
Azure dev ops meetup one
Nicolò Carandini
 
APPSTUDIO: DA ZERO ALLO STORE IN 50 MINUTI!
APPSTUDIO: DA ZERO ALLO STORE IN 50 MINUTI!APPSTUDIO: DA ZERO ALLO STORE IN 50 MINUTI!
APPSTUDIO: DA ZERO ALLO STORE IN 50 MINUTI!
DotNetCampus
 
Web Api – The HTTP Way
Web Api – The HTTP WayWeb Api – The HTTP Way
Web Api – The HTTP WayLuca Milan
 
Introduzione ad ASP.NET Core
Introduzione ad ASP.NET CoreIntroduzione ad ASP.NET Core
Introduzione ad ASP.NET Core
Andrea Dottor
 

What's hot (19)

Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
Back to the Future: Migrare da WebForm ad ASP.NET Core gradualmente
 
DotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql ServerDotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql Server
 
Sviluppo Web con React e Delphi - Seminario Delphi Day 2016, Piacenza
Sviluppo Web con React e Delphi - Seminario Delphi Day 2016, PiacenzaSviluppo Web con React e Delphi - Seminario Delphi Day 2016, Piacenza
Sviluppo Web con React e Delphi - Seminario Delphi Day 2016, Piacenza
 
Alla scoperta di gRPC
Alla scoperta di gRPCAlla scoperta di gRPC
Alla scoperta di gRPC
 
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
 
Blazor per uno sviluppatore Web Form
Blazor per uno sviluppatore Web FormBlazor per uno sviluppatore Web Form
Blazor per uno sviluppatore Web Form
 
Angularjs
AngularjsAngularjs
Angularjs
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
AntiPatterns: i vizi del programmatore
AntiPatterns: i vizi del programmatoreAntiPatterns: i vizi del programmatore
AntiPatterns: i vizi del programmatore
 
Delphi & Dintorni Webinar - Diventa un mago del Testing
Delphi & Dintorni Webinar - Diventa un mago del TestingDelphi & Dintorni Webinar - Diventa un mago del Testing
Delphi & Dintorni Webinar - Diventa un mago del Testing
 
Dot netcampus2015 green-template
Dot netcampus2015 green-templateDot netcampus2015 green-template
Dot netcampus2015 green-template
 
ASP.NET MVC 6 - uno sguardo al futuro
ASP.NET MVC 6 - uno sguardo al futuroASP.NET MVC 6 - uno sguardo al futuro
ASP.NET MVC 6 - uno sguardo al futuro
 
Cosa c'è di nuovo in asp.net core 2 0
Cosa c'è di nuovo in asp.net core 2 0Cosa c'è di nuovo in asp.net core 2 0
Cosa c'è di nuovo in asp.net core 2 0
 
ASP.NET MVC: sfruttare la piattaforma al 100%
ASP.NET MVC: sfruttare la piattaforma al 100%ASP.NET MVC: sfruttare la piattaforma al 100%
ASP.NET MVC: sfruttare la piattaforma al 100%
 
Dependency injection questa sconosciuta
Dependency injection questa sconosciutaDependency injection questa sconosciuta
Dependency injection questa sconosciuta
 
Azure dev ops meetup one
Azure dev ops meetup oneAzure dev ops meetup one
Azure dev ops meetup one
 
APPSTUDIO: DA ZERO ALLO STORE IN 50 MINUTI!
APPSTUDIO: DA ZERO ALLO STORE IN 50 MINUTI!APPSTUDIO: DA ZERO ALLO STORE IN 50 MINUTI!
APPSTUDIO: DA ZERO ALLO STORE IN 50 MINUTI!
 
Web Api – The HTTP Way
Web Api – The HTTP WayWeb Api – The HTTP Way
Web Api – The HTTP Way
 
Introduzione ad ASP.NET Core
Introduzione ad ASP.NET CoreIntroduzione ad ASP.NET Core
Introduzione ad ASP.NET Core
 

Viewers also liked

Disegnare Web Application orientate al Mobile con MVC 4 e jQuery Mobile (We W...
Disegnare Web Application orientate al Mobile con MVC 4 e jQuery Mobile (We W...Disegnare Web Application orientate al Mobile con MVC 4 e jQuery Mobile (We W...
Disegnare Web Application orientate al Mobile con MVC 4 e jQuery Mobile (We W...
Giorgio Di Nardo
 
Windows Phone 7 Development
Windows Phone 7 DevelopmentWindows Phone 7 Development
Windows Phone 7 Development
Claudio Gandelli
 
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
Marco Parenzan
 
ASP.NET
ASP.NETASP.NET
What's New in ASP.NET 4.5 and Visual Studio 2012
What's New in ASP.NET 4.5 and Visual Studio 2012What's New in ASP.NET 4.5 and Visual Studio 2012
What's New in ASP.NET 4.5 and Visual Studio 2012
Andrea Dottor
 
Hands on MVC - Mastering the Web
Hands on MVC - Mastering the WebHands on MVC - Mastering the Web
Hands on MVC - Mastering the Web
Claudio Gandelli
 
Crea servizi REST per la tua App con ASP.NET 5
Crea servizi REST per la tua App con ASP.NET 5Crea servizi REST per la tua App con ASP.NET 5
Crea servizi REST per la tua App con ASP.NET 5
Andrea Dottor
 
Pine survey report [compatibility mode]
Pine survey report [compatibility mode]Pine survey report [compatibility mode]
Pine survey report [compatibility mode]
Rim View Consulting
 

Viewers also liked (8)

Disegnare Web Application orientate al Mobile con MVC 4 e jQuery Mobile (We W...
Disegnare Web Application orientate al Mobile con MVC 4 e jQuery Mobile (We W...Disegnare Web Application orientate al Mobile con MVC 4 e jQuery Mobile (We W...
Disegnare Web Application orientate al Mobile con MVC 4 e jQuery Mobile (We W...
 
Windows Phone 7 Development
Windows Phone 7 DevelopmentWindows Phone 7 Development
Windows Phone 7 Development
 
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
 
ASP.NET
ASP.NETASP.NET
ASP.NET
 
What's New in ASP.NET 4.5 and Visual Studio 2012
What's New in ASP.NET 4.5 and Visual Studio 2012What's New in ASP.NET 4.5 and Visual Studio 2012
What's New in ASP.NET 4.5 and Visual Studio 2012
 
Hands on MVC - Mastering the Web
Hands on MVC - Mastering the WebHands on MVC - Mastering the Web
Hands on MVC - Mastering the Web
 
Crea servizi REST per la tua App con ASP.NET 5
Crea servizi REST per la tua App con ASP.NET 5Crea servizi REST per la tua App con ASP.NET 5
Crea servizi REST per la tua App con ASP.NET 5
 
Pine survey report [compatibility mode]
Pine survey report [compatibility mode]Pine survey report [compatibility mode]
Pine survey report [compatibility mode]
 

Similar to ASP.NET MVC: Andare oltre il 100% (Web@work)

Slide typescript - xe dotnet - Codemotion Rome 2015
Slide typescript - xe dotnet - Codemotion Rome 2015Slide typescript - xe dotnet - Codemotion Rome 2015
Slide typescript - xe dotnet - Codemotion Rome 2015Codemotion
 
Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010
Mauro Servienti
 
Cert03 70-486 developing asp.net mvc 4 web applications
Cert03   70-486 developing asp.net mvc 4 web applicationsCert03   70-486 developing asp.net mvc 4 web applications
Cert03 70-486 developing asp.net mvc 4 web applicationsDotNetCampus
 
TYPESCRIPT, ANGULAR E BOOTSTRAP ASSIEME PER APPLICAZIONI REAL WORLD
TYPESCRIPT, ANGULAR E BOOTSTRAP ASSIEME PER APPLICAZIONI REAL WORLDTYPESCRIPT, ANGULAR E BOOTSTRAP ASSIEME PER APPLICAZIONI REAL WORLD
TYPESCRIPT, ANGULAR E BOOTSTRAP ASSIEME PER APPLICAZIONI REAL WORLD
DotNetCampus
 
Agileday2013 pratiche agili applicate all'infrastruttura
Agileday2013 pratiche agili applicate all'infrastrutturaAgileday2013 pratiche agili applicate all'infrastruttura
Agileday2013 pratiche agili applicate all'infrastruttura
XPeppers
 
Powerful asp.net 4 e ie9
Powerful asp.net 4 e ie9Powerful asp.net 4 e ie9
Powerful asp.net 4 e ie9
Stefano Benedetti
 
Cert04 70-484 - essentials of developing windows store apps
Cert04   70-484 - essentials of developing windows store appsCert04   70-484 - essentials of developing windows store apps
Cert04 70-484 - essentials of developing windows store appsDotNetCampus
 
Web app slots and WebAPI versioning
Web app slots and WebAPI versioningWeb app slots and WebAPI versioning
Web app slots and WebAPI versioning
Nicolò Carandini
 
Web app slots and webapi versioning
Web app slots and webapi versioningWeb app slots and webapi versioning
Web app slots and webapi versioning
Nicolò Carandini
 
Design Patterns - enterprise patterns (part I)
Design Patterns - enterprise patterns (part I)Design Patterns - enterprise patterns (part I)
Design Patterns - enterprise patterns (part I)
Fabio Armani
 
Introduzione ai Coded UI Tests
Introduzione ai Coded UI TestsIntroduzione ai Coded UI Tests
Introduzione ai Coded UI Tests
Pietro Libro
 
Blazor ha vinto? Storie di casi reali
Blazor ha vinto? Storie di casi realiBlazor ha vinto? Storie di casi reali
Blazor ha vinto? Storie di casi reali
Andrea Dottor
 
OpenDevSecOps 2019 - Open devsecops un caso di studio
OpenDevSecOps 2019 - Open devsecops un caso di studioOpenDevSecOps 2019 - Open devsecops un caso di studio
OpenDevSecOps 2019 - Open devsecops un caso di studio
Emerasoft, solutions to collaborate
 
Le novita di visual studio 2012
Le novita di visual studio 2012Le novita di visual studio 2012
Le novita di visual studio 2012Crismer La Pignola
 
ASP.NET 4.6 e ASP.NET 5...l'evoluzione del web
ASP.NET 4.6 e ASP.NET 5...l'evoluzione del webASP.NET 4.6 e ASP.NET 5...l'evoluzione del web
ASP.NET 4.6 e ASP.NET 5...l'evoluzione del web
Andrea Dottor
 
Blazor with .net 5 - di Gerardo Greco
Blazor with .net 5 - di Gerardo GrecoBlazor with .net 5 - di Gerardo Greco
Blazor with .net 5 - di Gerardo Greco
Giuneco S.r.l
 
Web api 2.0
Web api 2.0Web api 2.0
Web api 2.0
Nicolò Carandini
 
Azure dayroma java, il lato oscuro del cloud
Azure dayroma   java, il lato oscuro del cloudAzure dayroma   java, il lato oscuro del cloud
Azure dayroma java, il lato oscuro del cloud
Riccardo Zamana
 
Fe04 angular js-101
Fe04   angular js-101Fe04   angular js-101
Fe04 angular js-101DotNetCampus
 
Web dynpro for abap 02
Web dynpro for abap 02Web dynpro for abap 02
Web dynpro for abap 02
Piergiorgio Bossù
 

Similar to ASP.NET MVC: Andare oltre il 100% (Web@work) (20)

Slide typescript - xe dotnet - Codemotion Rome 2015
Slide typescript - xe dotnet - Codemotion Rome 2015Slide typescript - xe dotnet - Codemotion Rome 2015
Slide typescript - xe dotnet - Codemotion Rome 2015
 
Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010Dal requisito all'implementazione @ CD2010
Dal requisito all'implementazione @ CD2010
 
Cert03 70-486 developing asp.net mvc 4 web applications
Cert03   70-486 developing asp.net mvc 4 web applicationsCert03   70-486 developing asp.net mvc 4 web applications
Cert03 70-486 developing asp.net mvc 4 web applications
 
TYPESCRIPT, ANGULAR E BOOTSTRAP ASSIEME PER APPLICAZIONI REAL WORLD
TYPESCRIPT, ANGULAR E BOOTSTRAP ASSIEME PER APPLICAZIONI REAL WORLDTYPESCRIPT, ANGULAR E BOOTSTRAP ASSIEME PER APPLICAZIONI REAL WORLD
TYPESCRIPT, ANGULAR E BOOTSTRAP ASSIEME PER APPLICAZIONI REAL WORLD
 
Agileday2013 pratiche agili applicate all'infrastruttura
Agileday2013 pratiche agili applicate all'infrastrutturaAgileday2013 pratiche agili applicate all'infrastruttura
Agileday2013 pratiche agili applicate all'infrastruttura
 
Powerful asp.net 4 e ie9
Powerful asp.net 4 e ie9Powerful asp.net 4 e ie9
Powerful asp.net 4 e ie9
 
Cert04 70-484 - essentials of developing windows store apps
Cert04   70-484 - essentials of developing windows store appsCert04   70-484 - essentials of developing windows store apps
Cert04 70-484 - essentials of developing windows store apps
 
Web app slots and WebAPI versioning
Web app slots and WebAPI versioningWeb app slots and WebAPI versioning
Web app slots and WebAPI versioning
 
Web app slots and webapi versioning
Web app slots and webapi versioningWeb app slots and webapi versioning
Web app slots and webapi versioning
 
Design Patterns - enterprise patterns (part I)
Design Patterns - enterprise patterns (part I)Design Patterns - enterprise patterns (part I)
Design Patterns - enterprise patterns (part I)
 
Introduzione ai Coded UI Tests
Introduzione ai Coded UI TestsIntroduzione ai Coded UI Tests
Introduzione ai Coded UI Tests
 
Blazor ha vinto? Storie di casi reali
Blazor ha vinto? Storie di casi realiBlazor ha vinto? Storie di casi reali
Blazor ha vinto? Storie di casi reali
 
OpenDevSecOps 2019 - Open devsecops un caso di studio
OpenDevSecOps 2019 - Open devsecops un caso di studioOpenDevSecOps 2019 - Open devsecops un caso di studio
OpenDevSecOps 2019 - Open devsecops un caso di studio
 
Le novita di visual studio 2012
Le novita di visual studio 2012Le novita di visual studio 2012
Le novita di visual studio 2012
 
ASP.NET 4.6 e ASP.NET 5...l'evoluzione del web
ASP.NET 4.6 e ASP.NET 5...l'evoluzione del webASP.NET 4.6 e ASP.NET 5...l'evoluzione del web
ASP.NET 4.6 e ASP.NET 5...l'evoluzione del web
 
Blazor with .net 5 - di Gerardo Greco
Blazor with .net 5 - di Gerardo GrecoBlazor with .net 5 - di Gerardo Greco
Blazor with .net 5 - di Gerardo Greco
 
Web api 2.0
Web api 2.0Web api 2.0
Web api 2.0
 
Azure dayroma java, il lato oscuro del cloud
Azure dayroma   java, il lato oscuro del cloudAzure dayroma   java, il lato oscuro del cloud
Azure dayroma java, il lato oscuro del cloud
 
Fe04 angular js-101
Fe04   angular js-101Fe04   angular js-101
Fe04 angular js-101
 
Web dynpro for abap 02
Web dynpro for abap 02Web dynpro for abap 02
Web dynpro for abap 02
 

ASP.NET MVC: Andare oltre il 100% (Web@work)

  • 1. ASP.NET MVC: Andare oltre il 100% Giorgio Di Nardo Proge-Software s.r.l. giorgio.dinardo@domusdotnet.org @akelitz http://blogs.ugidotnet.org/akelitz Web@Work
  • 3. Web@Work Agenda • NuGet • Url localization • Dependency Resolver • Unit testing
  • 4. Web@Work NuGet Aggiungere un riferimento Aggiungere un riferimento senza NuGet con NuGet Trovarlo Scaricarlo Estrarlo Aggiungere pacchetto Referenziarlo Configurarlo
  • 5. Web@Work NuGet • Un Package Manager per .NET e Visual Studio • Installabile tramite Extension Manager • Utilizzabile tramite: • GUI • Console PowerShell • Tool a riga di comando • Supporta sorgenti multiple (pubbliche e private)
  • 6. Ciclo di vita di una richiesta Web@Work con ASP.NET MVC Model Request Action Response Binder URL Action Controller View Routing Filter HTTP Controller Action View Handler Factory Result Engine
  • 7. Web@Work Localizzazione • Processo attraverso il quale è possibile fornire il contenuto della nostra applicazione in diverse lingue senza dover riscrivere tutto • Tipicamente ottenuto per mezzo di file di risorsa tradotti nelle varie lingue da supportare • Disponibile out-of-the-box con ASP.NET
  • 9. Web@Work Singly Registered Services • IControllerActivator • DefaultControllerActivator • IControllerFactory (ControllerBuilder.Current.SetControllerFact ory) • DefaultControllerFactory • IViewPageActivator • DefaultViewPageActivator • ModelMetadataProvider (ModelMetadataProviders.Current) • DataAnnotationsModelMetadataProvider
  • 10. Multiply Registered Services Web@Work (cooperative) • IFilterProvider (FilterProviders.Providers) • FilterAttributeFilterProvider • GlobalFilterCollection • ControllerInstanceFilterProvider • ModelValidatorProvider (ModelValidatorProviders.Providers) • DataAnnotationsModelValidatorProvider • DataErrorInfoModelValidatorProvider • ClientDataTypeModelValidatorProvider
  • 11. Multiply Registered Services Web@Work (competitive) • IModelBinderProvider (ModelBinderProviders.BinderProviders) • DefaultControllerFactory • IViewEngine (ViewEngines.Engines) • WebFormViewEngine • RazorViewEngine • ValueProviderFactory (ValueProviderFactories.Factories) • ChildActionValueProviderFactory • FormValueProviderFactory • JsonValueProviderFactory • RouteDataValueProviderFactory • QueryStringValueProviderFactory • HttpFileCollectionValueProviderFactory
  • 12. Web@Work Dependency Resolver • Consente di risolvere i problemi di dipendenza • Concretizzazione del pattern astratto Inversion-of-Control (IoC) • Permette di incapsulare facilmente uno IoC Container • Molte implementazioni disponibili su NuGet
  • 13. Web@Work Dipendenze e IoC • Il componente A da passivo (subisce la scelta di B di usare C)... Componente Componente Servizio A B C • ...diventa attivo (impone a B di usare D per svolgere un azione di tipo IC) Componente Servizio Componente A D : IC B
  • 16. Web@Work Service Locator • Il pattern Service Locator implementa l’astrazione di IoC definendo un componente esterno responsabile della risoluzione delle dipendenze • Un Service Locator può essere: • Specifico: consente la risoluzione strongly typed di interfacce ben definite • Generico: fornisce un approccio generico per la risoluzione di qualunque tipo di dipendenza
  • 18. Web@Work SL specifici: pregi e difetti • È facile da capire e utilizzare • Consente di personalizzare la creazione degli oggetti usando parametri • È limitato alla creazione degli oggetti previsti in fase di design • Rischia di trasformare la sua manutenzione in un incubo
  • 20. Web@Work SL generici: pregi e difetti • Risolve ogni tipo di dipendenza anche senza conoscere il tipo di oggetto richiesto • Riduce i costi di manutenzione, non richiedendo la modifica dell’interfaccia • Non fornisce informazioni qualitative sui servizi che eroga (o che non eroga) • Non consente di personalizzare la creazione degli oggetti restituiti
  • 21. Web@Work Dependency Injection • Implementazione di IoC basata sulla realizzazione dei componenti in modo tale da consentire un’esplicità indicazione delle dipendenze dall’esterno • Rispetto a SL consente una trasparenza del codice nettamente maggiore • Può essere declinata in due varianti: • Constructor Injection • Property Injection
  • 22. Web@Work DI: Constructor Injection • Forma più comune di Dependency Injection • Il costruttore del componente specifica esplicitamente tutte le sue dipendenze • Il componente non deve conoscere i dettagli di funzionamento del Service Locator • L’utilizzo del componente è chiaro con un semplice sguardo al costruttore
  • 23. Web@Work DI: Property Injection • Forma meno comune di Dependency Injection • Le dipendenze possono essere iniettate impostando proprietà apposite • È meno chiaro che prima di utilizzare un metodo del componente bisogna settare una proprietà • Consente di specificare dipendenze opzionali • Unica scelta se non si può gestire la chiamata al costruttore
  • 24. Web@Work Dependency Injection Containers • Entrambi i metodi dicono «cosa» fare ma non «come» farlo: la risposta è nei DI Container • Sono librerie che agiscono come Factory dei componenti analizzando automaticamente le dipendenze • Simili nell’aspetto esterno ai SL si prendono però carico anche della creazione dell’oggetto da restituire
  • 26. Web@Work Testing, Unit testing e TDD • Parte dello sviluppo software che si occupa della verifica delle corrispondenza tra il funzionamento del codice e i requisiti • Unit testing, integration testing, performance testing, scalability testing • Consente di migliorare la qualità del proprio codice, ridurre il peso della manutenzione ma anche (TDD) migliorarne il design
  • 27. Web@Work Pilastri dello Unit testing • Testare piccoli frammenti di codice («unit»), tipicamente metodi • Testare in maniera isolata rispetto al resto dell’applicazione • Testare i soli endpoint pubblici • Ottenere il risultato positivo/negativo dei test in maniera automatizzata
  • 28. Web@Work Test Driven Design • Utilizzare lo Unit testing per guidare lo sviluppo della propria applicazione • Scrivere il codice strettamente necessario a passare i test • Red/Green cycle • Utilizzabile sia per i nuovi sviluppi che per il bug fixing • Attenzione al refactoring!
  • 29. Web@Work Arrange, Act, Assert • Arrange: predisporre l’ambiente per il test • Act: effettuare la chiamata al codice oggetto del test • Assert: verificare che ciò che ci si aspettava si è verificato (e ciò che non ci si aspettava non si è verificato) • Verificare un comportamente alla volta (single assertion rule)

Editor's Notes

  1. 2 problemi: test e limitazionefunzionalità
  2. Possibilità di far fare al metodocose diverse (sms, email, ecc.)Possibilità di testareilmetodo
  3. The service locator pattern says that inversion of control is achieved by having components get theirdependencies through an external component known as the service locator. Sometimes a servicelocator is a very specific interface, with strongly typed requests for specific services, and sometimesit may show up as a very generic way to request services of any arbitrary type.
  4. In this case, when you need an implementation of IServiceLocator, you know to callGetMessageSender. The method returns exactly IMessageSender, so you won’t need to castthe result.You’ll notice that I’m showing the service locator as an interface here rather than as a concrete type.Remember that one of your goals is to reduce the tight coupling between components; this includesthe coupling between the consumer code and the service locator itself. If the consumer code is codedagainst IServiceLocator, that means you can substitute alternative implementations at run time asappropriate. This can have tremendous value in unit testing.Now if you re-write NotificationSystem in terms of the strongly typed service locator, it mightlook like this.We’re assuming that anybody who creates an instance of NotificationSystem will haveaccess to a service locator.
  5. public interface IServiceLocator{IMessagingService GetMessagingService();}
  6. In this case, when you need an implementation of IServiceLocator, you know to callGetMessageSender. The method returns exactly IMessageSender, so you won’t need to castthe result.You’ll notice that I’m showing the service locator as an interface here rather than as a concrete type.Remember that one of your goals is to reduce the tight coupling between components; this includesthe coupling between the consumer code and the service locator itself. If the consumer code is codedagainst IServiceLocator, that means you can substitute alternative implementations at run time asappropriate. This can have tremendous value in unit testing.Now if you re-write NotificationSystem in terms of the strongly typed service locator, it mightlook like this.We’re assuming that anybody who creates an instance of NotificationSystem will haveaccess to a service locator.
  7. Why might you choose a weakly typed locator? It allows you to fi x many of the downsides of thestrongly typed locator; that is, you get an interface that can create arbitrary types without knowingabout them ahead of time, and it reduces your maintenance burden because the interface is not constantlyevolving.On the other hand, a weakly typed locator interface doesn’t really communicate anything aboutthe kinds of services that might be requested, and it doesn’t offer a simple way to customize the creationof the service. You could add an arbitrary optional array of objects as “creation parameters”
  8. Non è il componente che cerca verso l’esterno un servizio che risolva le dipendenze ma è la chiamata dall’esterno che fornisce al componente la risoluzione delle dipendenze.The dependency injection (DI) pattern is another form of the inversion of control pattern, whereinthere is no intermediary object like the service locator. Instead, components are written in a waythat allows their dependencies to be stated explicitly, usually by way of constructor parameters orproperty setters.Developers who choose dependency injection over service location are often making a consciousdecision to choose transparency of requirements over opacity. Choosing the transparency of dependencyinjection also has signifi cant advantages during unit testing, as discussed in the next chapter.
  9. The most common form of dependency injection is called constructor injection. This techniqueinvolves creating a constructor for your class that expresses all of its dependencies explicitly (asopposed to the previous service location examples, where your constructor took the service locatoras its only constructor parameter).In this code, the fi rstbenefi t is that the implementation of the constructor is dramatically simplifi ed.The component is always expecting whoever creates it to pass the required dependencies. It onlyneeds to store the instance of IMessagingService for later use.Another benefi t is that you’ve reduced the number of things NotificationSystem needs to knowabout. Previously, it needed to understand service locators in addition to its own dependencies; now,it is focused solely on its own dependencies.The third benefi t, as alluded to previously, is this new transparency of requirements. Any code thatwants to create an instance of NotificationSystem can look at the constructor and know exactlywhat kinds of things are necessary to make NotificationSystem function. There is no guessworkand no indirection through the service locator.
  10. A less common form of dependency injection is called property injection. As the name implies,dependencies for a class are injected by setting public properties on the object rather than throughthe use of constructor parameters.This class expects any consumers to provide you with your dependenciesvia properties rather than the constructor.The InterestingEventHappened method is now slightly dangerous. It presumes that the servicedependency has already been provided; if it hasn’t, then it will throw a NullReferenceException.You should update the InterestingEventHappened method to ensure that it has been providedwith its dependency before using the service.It should be obvious that you’ve slightly reduced your transparency of requirements here; it’s not quiteas opaque as using the service locator, but it’s definitely more error prone than constructor injection.With this reduced transparency, you’re probably wondering why a developer would choose propertyinjection over constructor injection. Two situations might warrant that choice:‰ If your dependencies are truly optional in the sense that you have some fallback when theconsumer doesn’t provide you with one, property injection is probably a good choice.‰ Instances of your class might be created in such a way that you don’t have control over theconstructor that’s being called. This is a less obvious reason. You’ll see a couple of examplesof this later in the chapter when we discuss how dependency injection is applied to view pages.In general, developers tend to favor using constructor injection whenever possible, falling back toproperty injection only when one of the preceding reasons dictates. Obviously, you can mix bothtechniques in a single object: put your mandatory dependencies in as constructor parameters, andyour optional dependencies in as properties.
  11. A dependency injection container is a software library that acts as a factory for components,automatically inspecting and fulfilling their dependency requirements.The consumption portion of theAPI for a dependency injection container looks a lot like a service locator because the primary actionyou ask it to perform is to provide you with some component, usually based on its type.The difference is in the details, of course. The implementation of a service locator is typically verysimple: You tell the service locator, “If anybody asks for this type, you give them this object.”Service locators are rarely involved in the process of actually creating the object in question. Adependency injection container, on the other hand, is often configured with logic like, “If anybodyasks for this type, you create an object of this concrete type and give them that.” The implication isthat creating the object of that concrete type will, in turn, often require the creation of other typesto fulfill its dependency requirements. This difference, while subtle, makes a fairly large differencein the actual usage of service locators versus dependency injection containers.
  12. A dependency injection container is a software library that acts as a factory for components,automatically inspecting and fulfilling their dependency requirements.The consumption portion of theAPI for a dependency injection container looks a lot like a service locator because the primary actionyou ask it to perform is to provide you with some component, usually based on its type.The difference is in the details, of course. The implementation of a service locator is typically verysimple: You tell the service locator, “If anybody asks for this type, you give them this object.”Service locators are rarely involved in the process of actually creating the object in question. Adependency injection container, on the other hand, is often configured with logic like, “If anybodyasks for this type, you create an object of this concrete type and give them that.” The implication isthat creating the object of that concrete type will, in turn, often require the creation of other typesto fulfill its dependency requirements. This difference, while subtle, makes a fairly large differencein the actual usage of service locators versus dependency injection containers.
  13. A dependency injection container is a software library that acts as a factory for components,automatically inspecting and fulfilling their dependency requirements.The consumption portion of theAPI for a dependency injection container looks a lot like a service locator because the primary actionyou ask it to perform is to provide you with some component, usually based on its type.The difference is in the details, of course. The implementation of a service locator is typically verysimple: You tell the service locator, “If anybody asks for this type, you give them this object.”Service locators are rarely involved in the process of actually creating the object in question. Adependency injection container, on the other hand, is often configured with logic like, “If anybodyasks for this type, you create an object of this concrete type and give them that.” The implication isthat creating the object of that concrete type will, in turn, often require the creation of other typesto fulfill its dependency requirements. This difference, while subtle, makes a fairly large differencein the actual usage of service locators versus dependency injection containers.
  14. A dependency injection container is a software library that acts as a factory for components,automatically inspecting and fulfilling their dependency requirements.The consumption portion of theAPI for a dependency injection container looks a lot like a service locator because the primary actionyou ask it to perform is to provide you with some component, usually based on its type.The difference is in the details, of course. The implementation of a service locator is typically verysimple: You tell the service locator, “If anybody asks for this type, you give them this object.”Service locators are rarely involved in the process of actually creating the object in question. Adependency injection container, on the other hand, is often configured with logic like, “If anybodyasks for this type, you create an object of this concrete type and give them that.” The implication isthat creating the object of that concrete type will, in turn, often require the creation of other typesto fulfill its dependency requirements. This difference, while subtle, makes a fairly large differencein the actual usage of service locators versus dependency injection containers.
  15. A dependency injection container is a software library that acts as a factory for components,automatically inspecting and fulfilling their dependency requirements.The consumption portion of theAPI for a dependency injection container looks a lot like a service locator because the primary actionyou ask it to perform is to provide you with some component, usually based on its type.The difference is in the details, of course. The implementation of a service locator is typically verysimple: You tell the service locator, “If anybody asks for this type, you give them this object.”Service locators are rarely involved in the process of actually creating the object in question. Adependency injection container, on the other hand, is often configured with logic like, “If anybodyasks for this type, you create an object of this concrete type and give them that.” The implication isthat creating the object of that concrete type will, in turn, often require the creation of other typesto fulfill its dependency requirements. This difference, while subtle, makes a fairly large differencein the actual usage of service locators versus dependency injection containers.