SlideShare une entreprise Scribd logo
1  sur  29
Four Other .NET Web Frameworks in Less Than an Hour



                                                 Christian Horsdal
                                                     @chr_horsdal
                                     http://horsdal.blogspot.com/
Who Am I?




     Lead Software Architect @ Mjølner Informatics
     Husband and Father
     Some who enjoys
       Clean code
       TDD‟ing
       When ‟GF wins
       Simplicity
       Whisky




3
Why?

     There are alternatives to ASP.NET
       Know them!



     Style matters

     Tradeoffs, tradeoffs, tradeoffs
       Conventions <-> explicitness
       DRY <-> separation of concerns
       Abstract <-> concrete




4
Why?



     Run anywhere

     IoC/DI to the bone

     Embrace HTTP

     OSS and community driven



5
What will you learn?

            A taste of some alternatives

                                  FubuMVC

                                  OpenRasta

                                  Nancy

                                  Frank




6
Sample




7
FubuMVC – At a glance

     One Model In One Model Out
       Aka OMIOMO
       Aka Russian Doll


     Convention over Configuration

     Really cool built-in diagnostics

     Everything is POCOs


8
FubuMVC – ShortUrl Overview
    GET “/”                    HomeController.get_Home             HomeView.cshtml

                                    • Returns                        • Takes
       • No params                    HomeViewModel                    HomeViewModel




      POST “/”
                           HomeController.post_Home              UrlShortenedView.cshtml
    • UrlShorteningModel
                                 • Takes                          • Takes
                                   UrlShorteningModel               UrlShorteningViewModel
                                 • Returns
                                   UrlShorteningViewModel



    GET “/42”                               HomeController.post_Home


                                                      • Takes ShortenedUrlMode
         • ShortenedUrlModel
                                                      • Returns FubuContinuation

9
FubuMVC – ShortUrl – Serving the FORM
public class HomeController
{
   public HomeController(UrlStore urlStore)
   {
     this.urlStore = urlStore;
   }
                                        @model ShortUrlInFubuMvc.HomeViewModel
   public HomeViewModel get_home()      @{
   {                                      Layout = null;
     return new HomeViewModel();        }
   }
                                        <!DOCTYPE html>
   …                                    <html>
}                                           <body>
                                              <form method="post" action="home">
 public class HomeViewModel { }                  <label>Url: </label>
                                                 <input type="text" name="url"/>
                                                 <input type="submit"
                                        value="shorten"/>
                                              </form>
10                                          </body>
FubuMVC – ShortUrl – POST the FORM
         public UrlShorteningViewModel post_home(UrlShorteningModel input)
         {
           var shortenedUrl = input.Url.GetHashCode().ToString();
           urlStore.SaveUrl(input.Url, shortenedUrl);

             return new UrlShorteningViewModel
                 {
                   Host = "localhost:51862",
                   HashCode = shortenedUrl
                 };
         }

       public class UrlShorteningModel
       {
         public string Url { get; set; }
       }

       public class UrlShorteningViewModel
       {
         public string Host { get; set; }
11       public string HashCode { get; set; }
FubuMVC – ShortUrl - Redirecting



            public FubuContinuation get_Url(ShortenedUrlModel input)
            {
              var longUrl = urlStore.GetUrlFor(input.Url) ?? "/notfound/";
              return FubuContinuation.RedirectTo(longUrl);
            }

          public class ShortenedUrlModel
           {
             public string Url { get; set; }
           }




12
OpenRasta– At a glance

      Three things:
        Resources
        Handlers
        Codecs


      Automatic conneg

      Everything is POCOs




13
OpenRasta – Shorturl Overview

      Resource:
         “/”
         “/{shortenedUrl}”
         Home
                                GET “/”     POST “/”      GET “/42”

      Handler
         HomeHandler


      “Codecs”                           Home resource
         WebForms viewengine             HomeHandler

         Form data




14
OpenRasta– ShortUrl – Serving the FORM
 public class HomeHandler
 {
   public HomeHandler(IRequest request, UrlStore urlStore)
   {
                                        public class Configuration : IConfigurationSource
     this.request = request;
                                         {
     this.urlStore = urlStore;
                                           public void Configure()
   }
                                           {
                                             using (OpenRastaConfiguration.Manual)
   public Home Get()
                                             {
   {
                                               ResourceSpace.Has
     return new Home();
                                                .ResourcesOfType<Home>()
   }
                                                .AtUri("/").And.AtUri("/home")
   …
                                                .And.AtUri("/{shortenedUrl}")
}
                                                .HandledBy<HomeHandler>()
                                                .RenderedByAspx("~/Views/Home.aspx");
public class Home
{
   public string LongUrl { get; set; }
                                               ResourceSpace.Uses
   public string ShortUrl { get; set; }
                                                .Resolver.AddDependencyInstance<UrlStore>
   public string Host { get; set; }
                                             }
}
15
                                           }
OpenRasta– ShortUrl – POST the FORM



           public Home Post(Home input)
           {
             input.ShortUrl = input.LongUrl.GetHashCode().ToString();
             input.Host = request.Uri.Host + ":" + request.Uri.Port;

               urlStore.SaveUrl(input.LongUrl, input.ShortUrl);

               return input;
           }




16
OpenRasta– ShortUrl - Redirecting



           public OperationResult Get(string shortenedUrl)
           {
             var longUrl = urlStore.GetUrlFor(shortenedUrl);
             if (longUrl != null)
               return new OperationResult.SeeOther
                            {
                              RedirectLocation = new Uri(longUrl)
                            };
             else
               return new OperationResult.NotFound();
           }




17
Nancy– At a glance

      Lightweight, low ceremony
         Just works
         But easily swappable


      DSLs

      Built in diagnostics

      Testability is first class


18
Nancy – Shorturl Overview

      Modules
         ShortUrlModule


      Routes
         Get[“/”]
         Post[“/”]
         Get[“/{shortenedUrl}”]    HTTP
                                             Routes
                                                      Handler
                                                                 Response
                                   request            function

      A lambda for each




19
Nancy– ShortUrl – Serving the FORM

     public class ShortUrlModule : NancyModule
     {
       public ShortUrlModule(UrlStore urlStore)
       {
          Get["/"] = _ => View["index.html"];
           …
       }
       …
     }                                 <!DOCTYPE html>
                                       <html>
                                          <body>
                                             <form method="post" action="home">
                                                <label>Url: </label>
                                                <input type="text" name="url"/>
                                                <input type="submit"
                                       value="shorten"/>
                                             </form>
                                          </body>
                                       </html>
20
Nancy– ShortUrl – POST the FORM

public class ShortUrlModule : NancyModule
{
   public ShortUrlModule(UrlStore urlStore)
   {
      Get["/"] = _ => View["index.html"];
      Post["/"] = _ => ShortenUrl(urlStore);
      …
   }
  private Response ShortenUrl(UrlStore urlStore)
  {
     string longUrl = Request.Form.url;
     var shortUrl = longUrl.GetHashCode().ToString();
     urlStore.SaveUrl(longUrl, shortUrl);

      return View["shortened_url", new { Request.Headers.Host, ShortUrl = shortUrl }];
  }
 …
}

21
Nancy– ShortUrl - Redirecting


     public class ShortUrlModule : NancyModule
     {
       public ShortUrlModule(UrlStore urlStore)
       {
          Get["/"] = _ => View["index.html"];
          Post["/"] = _ => ShortenUrl(urlStore);
          Get["/{shorturl}"] = param =>
           {
              string shortUrl = param.shorturl;
              return Response.AsRedirect(urlStore.GetUrlFor(shortUrl.ToString()));
           };
       }
     …
     }




22
Frank– At a glance

      F#

      Bare bones approach to HTTP services

      Leverage WebAPI

      Compositional




23
Frank– ShortUrl – Serving the FORM

     let urlShortenerView = @"<!doctype html><meta charset=utf-8>
       <title>Hello</title>
       <p>Hello, world!
       <form action=""/"" method=""post"" enctype=""multipart/form-data"">
       <input type=""input"" name=""longUrl"" value=""long url"">
       <input type=""submit"">"

     let urlShortenerForm request = async {
       return respond HttpStatusCode.OK
                 (new StringContent(urlShortenerView,
                                     System.Text.Encoding.UTF8, "text/html"))
                 <| ``Content-Type`` "text/html"
     }




24
Frank– ShortUrl – POST the FORM


     let createShortUrl (request: HttpRequestMessage) = async {
       let! value = request.Content.AsyncReadAsMultipart()
       let longUrl = value.FirstDispositionNameOrDefault("longUrl")
                          .ReadAsStringAsync().Result;
       let urlKey = longUrl.GetHashCode().ToString()

         urlStore.Add(urlKey, longUrl)

         let shortUrl = baseUri + "/" + longUrl.GetHashCode().ToString()
         return respond HttpStatusCode.OK
                   (new StringContent(shortUrlCreatedView(shortUrl),
                                          System.Text.Encoding.UTF8, "text/html"))
                    <| ``Content-Type`` "text/html"
     }




25
Frank– ShortUrl - Redirecting


   let getShortUrl (request: HttpRequestMessage) = async {
     let urlKey = request
                    .RequestUri
                    .Segments.[request.RequestUri.Segments.Length - 1]
     let longUrl = urlStore.[urlKey]

       return respond HttpStatusCode.Redirect
                 (new EmptyContent())
                 <| Location (new Uri(longUrl))
   }


let rootResource = routeResource "/" [ get urlShortenerForm <|> post createShortUrl ]
let redirectReource = routeResource "/{shortUrl}" [ get getShortUrl ]

let app = merge [ rootResource; redirectReource ]

let config = new HttpSelfHostConfiguration(baseUri)
config.Register app
26
Why, again?


      There are alternatives to ASP.NET
        Know them!



      Style matters

      Tradeoffs, tradeoffs, tradeoffs




27
What might you have learned?

            A taste of some altenatives
                          FubuMVC
                             OMIOMU


                          OpenRasta
                             Resources, Handlers, Codecs


                          Nancy
                             DSL


                          Frank
                             F#
28
FubuMVC, OpenRasta, Nancy, Frank

WHEN, WHAT, WHERE?


        29
Evaluation page: http://bit.ly/cd2012b2
Please fill in!                 „kthxbai

Contenu connexe

Tendances

Jersey framework
Jersey frameworkJersey framework
Jersey framework
knight1128
 
Refactoring Jdbc Programming
Refactoring Jdbc ProgrammingRefactoring Jdbc Programming
Refactoring Jdbc Programming
chanwook Park
 
Tips
TipsTips
Tips
mclee
 

Tendances (20)

Mobyle administrator workshop
Mobyle administrator workshopMobyle administrator workshop
Mobyle administrator workshop
 
Dispatch in Clojure
Dispatch in ClojureDispatch in Clojure
Dispatch in Clojure
 
NodeJs
NodeJsNodeJs
NodeJs
 
Hadoop
HadoopHadoop
Hadoop
 
NIO and NIO2
NIO and NIO2NIO and NIO2
NIO and NIO2
 
Getting Started with PL/Proxy
Getting Started with PL/ProxyGetting Started with PL/Proxy
Getting Started with PL/Proxy
 
4 sesame
4 sesame4 sesame
4 sesame
 
ROracle
ROracle ROracle
ROracle
 
Tornadoweb
TornadowebTornadoweb
Tornadoweb
 
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Alfresco the clojure way -- Slides from the Alfresco DevCon2011Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
 
Jersey framework
Jersey frameworkJersey framework
Jersey framework
 
Data Processing Inside PostgreSQL
Data Processing Inside PostgreSQLData Processing Inside PostgreSQL
Data Processing Inside PostgreSQL
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web Services
 
WWHF 2018 - Using PowerUpSQL and goddi for Active Directory Information Gathe...
WWHF 2018 - Using PowerUpSQL and goddi for Active Directory Information Gathe...WWHF 2018 - Using PowerUpSQL and goddi for Active Directory Information Gathe...
WWHF 2018 - Using PowerUpSQL and goddi for Active Directory Information Gathe...
 
Writing Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason LeeWriting Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason Lee
 
Refactoring Jdbc Programming
Refactoring Jdbc ProgrammingRefactoring Jdbc Programming
Refactoring Jdbc Programming
 
PostgreSQL and PL/Java
PostgreSQL and PL/JavaPostgreSQL and PL/Java
PostgreSQL and PL/Java
 
Tips
TipsTips
Tips
 
The Beauty and the Beast
The Beauty and the BeastThe Beauty and the Beast
The Beauty and the Beast
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 

Similaire à Four .NET Web Frameworks in Less Than an Hour

Scala for scripting
Scala for scriptingScala for scripting
Scala for scripting
day
 
Scala4sling
Scala4slingScala4sling
Scala4sling
day
 
Wed 1630 greene_robert_color
Wed 1630 greene_robert_colorWed 1630 greene_robert_color
Wed 1630 greene_robert_color
DATAVERSITY
 
Designing a JavaFX Mobile application
Designing a JavaFX Mobile applicationDesigning a JavaFX Mobile application
Designing a JavaFX Mobile application
Fabrizio Giudici
 
Beginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCABeginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCA
Whymca
 

Similaire à Four .NET Web Frameworks in Less Than an Hour (20)

Solid Software Design Principles
Solid Software Design PrinciplesSolid Software Design Principles
Solid Software Design Principles
 
6976.ppt
6976.ppt6976.ppt
6976.ppt
 
TDC2016SP - Trilha .NET
TDC2016SP - Trilha .NETTDC2016SP - Trilha .NET
TDC2016SP - Trilha .NET
 
Scala for scripting
Scala for scriptingScala for scripting
Scala for scripting
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
 
Scala4sling
Scala4slingScala4sling
Scala4sling
 
SOLID
SOLIDSOLID
SOLID
 
Scala for scripting
Scala for scriptingScala for scripting
Scala for scripting
 
Unit testing
Unit testingUnit testing
Unit testing
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
 
iOS5 NewStuff
iOS5 NewStuffiOS5 NewStuff
iOS5 NewStuff
 
Writing Ansible Modules (DENOG11)
Writing Ansible Modules (DENOG11)Writing Ansible Modules (DENOG11)
Writing Ansible Modules (DENOG11)
 
CDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptorCDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptor
 
Wed 1630 greene_robert_color
Wed 1630 greene_robert_colorWed 1630 greene_robert_color
Wed 1630 greene_robert_color
 
Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)
 
Designing a JavaFX Mobile application
Designing a JavaFX Mobile applicationDesigning a JavaFX Mobile application
Designing a JavaFX Mobile application
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Flamingo Training - Hello World
Flamingo Training - Hello WorldFlamingo Training - Hello World
Flamingo Training - Hello World
 
Beginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCABeginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCA
 
PHPUnit your bug exterminator
PHPUnit your bug exterminatorPHPUnit your bug exterminator
PHPUnit your bug exterminator
 

Plus de Christian Horsdal

Nancy - A Lightweight .NET Web Framework
Nancy - A Lightweight .NET Web FrameworkNancy - A Lightweight .NET Web Framework
Nancy - A Lightweight .NET Web Framework
Christian Horsdal
 
DCI ANUG - 24th November 2010
DCI ANUG - 24th November 2010DCI ANUG - 24th November 2010
DCI ANUG - 24th November 2010
Christian Horsdal
 
DCI - ANUG 24th November 2010
DCI - ANUG 24th November 2010DCI - ANUG 24th November 2010
DCI - ANUG 24th November 2010
Christian Horsdal
 

Plus de Christian Horsdal (13)

Testing microservices.ANUG.20230111.pptx
Testing microservices.ANUG.20230111.pptxTesting microservices.ANUG.20230111.pptx
Testing microservices.ANUG.20230111.pptx
 
Scoping microservices.20190917
Scoping microservices.20190917Scoping microservices.20190917
Scoping microservices.20190917
 
Event sourcing anug 20190227
Event sourcing anug 20190227Event sourcing anug 20190227
Event sourcing anug 20190227
 
Consolidating services with middleware - NDC London 2017
Consolidating services with middleware - NDC London 2017Consolidating services with middleware - NDC London 2017
Consolidating services with middleware - NDC London 2017
 
Intro to.net core 20170111
Intro to.net core   20170111Intro to.net core   20170111
Intro to.net core 20170111
 
Middleware webnextconf - 20152609
Middleware   webnextconf - 20152609Middleware   webnextconf - 20152609
Middleware webnextconf - 20152609
 
Campus days 2014 owin
Campus days 2014 owinCampus days 2014 owin
Campus days 2014 owin
 
ASP.NET vNext ANUG 20140817
ASP.NET vNext ANUG 20140817ASP.NET vNext ANUG 20140817
ASP.NET vNext ANUG 20140817
 
Lightweight Approach to Building Web APIs with .NET
Lightweight Approach to Building Web APIs with .NETLightweight Approach to Building Web APIs with .NET
Lightweight Approach to Building Web APIs with .NET
 
Three Other Web Frameworks. All .NET. All OSS. One Hour. Go
Three Other Web Frameworks. All .NET. All OSS. One Hour. GoThree Other Web Frameworks. All .NET. All OSS. One Hour. Go
Three Other Web Frameworks. All .NET. All OSS. One Hour. Go
 
Nancy - A Lightweight .NET Web Framework
Nancy - A Lightweight .NET Web FrameworkNancy - A Lightweight .NET Web Framework
Nancy - A Lightweight .NET Web Framework
 
DCI ANUG - 24th November 2010
DCI ANUG - 24th November 2010DCI ANUG - 24th November 2010
DCI ANUG - 24th November 2010
 
DCI - ANUG 24th November 2010
DCI - ANUG 24th November 2010DCI - ANUG 24th November 2010
DCI - ANUG 24th November 2010
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Four .NET Web Frameworks in Less Than an Hour

  • 1. Four Other .NET Web Frameworks in Less Than an Hour Christian Horsdal @chr_horsdal http://horsdal.blogspot.com/
  • 2. Who Am I?  Lead Software Architect @ Mjølner Informatics  Husband and Father  Some who enjoys  Clean code  TDD‟ing  When ‟GF wins  Simplicity  Whisky 3
  • 3. Why?  There are alternatives to ASP.NET  Know them!  Style matters  Tradeoffs, tradeoffs, tradeoffs  Conventions <-> explicitness  DRY <-> separation of concerns  Abstract <-> concrete 4
  • 4. Why?  Run anywhere  IoC/DI to the bone  Embrace HTTP  OSS and community driven 5
  • 5. What will you learn? A taste of some alternatives  FubuMVC  OpenRasta  Nancy  Frank 6
  • 7. FubuMVC – At a glance  One Model In One Model Out  Aka OMIOMO  Aka Russian Doll  Convention over Configuration  Really cool built-in diagnostics  Everything is POCOs 8
  • 8. FubuMVC – ShortUrl Overview GET “/” HomeController.get_Home HomeView.cshtml • Returns • Takes • No params HomeViewModel HomeViewModel POST “/” HomeController.post_Home UrlShortenedView.cshtml • UrlShorteningModel • Takes • Takes UrlShorteningModel UrlShorteningViewModel • Returns UrlShorteningViewModel GET “/42” HomeController.post_Home • Takes ShortenedUrlMode • ShortenedUrlModel • Returns FubuContinuation 9
  • 9. FubuMVC – ShortUrl – Serving the FORM public class HomeController { public HomeController(UrlStore urlStore) { this.urlStore = urlStore; } @model ShortUrlInFubuMvc.HomeViewModel public HomeViewModel get_home() @{ { Layout = null; return new HomeViewModel(); } } <!DOCTYPE html> … <html> } <body> <form method="post" action="home"> public class HomeViewModel { } <label>Url: </label> <input type="text" name="url"/> <input type="submit" value="shorten"/> </form> 10 </body>
  • 10. FubuMVC – ShortUrl – POST the FORM public UrlShorteningViewModel post_home(UrlShorteningModel input) { var shortenedUrl = input.Url.GetHashCode().ToString(); urlStore.SaveUrl(input.Url, shortenedUrl); return new UrlShorteningViewModel { Host = "localhost:51862", HashCode = shortenedUrl }; } public class UrlShorteningModel { public string Url { get; set; } } public class UrlShorteningViewModel { public string Host { get; set; } 11 public string HashCode { get; set; }
  • 11. FubuMVC – ShortUrl - Redirecting public FubuContinuation get_Url(ShortenedUrlModel input) { var longUrl = urlStore.GetUrlFor(input.Url) ?? "/notfound/"; return FubuContinuation.RedirectTo(longUrl); } public class ShortenedUrlModel { public string Url { get; set; } } 12
  • 12. OpenRasta– At a glance  Three things:  Resources  Handlers  Codecs  Automatic conneg  Everything is POCOs 13
  • 13. OpenRasta – Shorturl Overview  Resource:  “/”  “/{shortenedUrl}”  Home GET “/” POST “/” GET “/42”  Handler  HomeHandler  “Codecs” Home resource  WebForms viewengine HomeHandler  Form data 14
  • 14. OpenRasta– ShortUrl – Serving the FORM public class HomeHandler { public HomeHandler(IRequest request, UrlStore urlStore) { public class Configuration : IConfigurationSource this.request = request; { this.urlStore = urlStore; public void Configure() } { using (OpenRastaConfiguration.Manual) public Home Get() { { ResourceSpace.Has return new Home(); .ResourcesOfType<Home>() } .AtUri("/").And.AtUri("/home") … .And.AtUri("/{shortenedUrl}") } .HandledBy<HomeHandler>() .RenderedByAspx("~/Views/Home.aspx"); public class Home { public string LongUrl { get; set; } ResourceSpace.Uses public string ShortUrl { get; set; } .Resolver.AddDependencyInstance<UrlStore> public string Host { get; set; } } } 15 }
  • 15. OpenRasta– ShortUrl – POST the FORM public Home Post(Home input) { input.ShortUrl = input.LongUrl.GetHashCode().ToString(); input.Host = request.Uri.Host + ":" + request.Uri.Port; urlStore.SaveUrl(input.LongUrl, input.ShortUrl); return input; } 16
  • 16. OpenRasta– ShortUrl - Redirecting public OperationResult Get(string shortenedUrl) { var longUrl = urlStore.GetUrlFor(shortenedUrl); if (longUrl != null) return new OperationResult.SeeOther { RedirectLocation = new Uri(longUrl) }; else return new OperationResult.NotFound(); } 17
  • 17. Nancy– At a glance  Lightweight, low ceremony  Just works  But easily swappable  DSLs  Built in diagnostics  Testability is first class 18
  • 18. Nancy – Shorturl Overview  Modules  ShortUrlModule  Routes  Get[“/”]  Post[“/”]  Get[“/{shortenedUrl}”] HTTP Routes Handler Response request function  A lambda for each 19
  • 19. Nancy– ShortUrl – Serving the FORM public class ShortUrlModule : NancyModule { public ShortUrlModule(UrlStore urlStore) { Get["/"] = _ => View["index.html"]; … } … } <!DOCTYPE html> <html> <body> <form method="post" action="home"> <label>Url: </label> <input type="text" name="url"/> <input type="submit" value="shorten"/> </form> </body> </html> 20
  • 20. Nancy– ShortUrl – POST the FORM public class ShortUrlModule : NancyModule { public ShortUrlModule(UrlStore urlStore) { Get["/"] = _ => View["index.html"]; Post["/"] = _ => ShortenUrl(urlStore); … } private Response ShortenUrl(UrlStore urlStore) { string longUrl = Request.Form.url; var shortUrl = longUrl.GetHashCode().ToString(); urlStore.SaveUrl(longUrl, shortUrl); return View["shortened_url", new { Request.Headers.Host, ShortUrl = shortUrl }]; } … } 21
  • 21. Nancy– ShortUrl - Redirecting public class ShortUrlModule : NancyModule { public ShortUrlModule(UrlStore urlStore) { Get["/"] = _ => View["index.html"]; Post["/"] = _ => ShortenUrl(urlStore); Get["/{shorturl}"] = param => { string shortUrl = param.shorturl; return Response.AsRedirect(urlStore.GetUrlFor(shortUrl.ToString())); }; } … } 22
  • 22. Frank– At a glance  F#  Bare bones approach to HTTP services  Leverage WebAPI  Compositional 23
  • 23. Frank– ShortUrl – Serving the FORM let urlShortenerView = @"<!doctype html><meta charset=utf-8> <title>Hello</title> <p>Hello, world! <form action=""/"" method=""post"" enctype=""multipart/form-data""> <input type=""input"" name=""longUrl"" value=""long url""> <input type=""submit"">" let urlShortenerForm request = async { return respond HttpStatusCode.OK (new StringContent(urlShortenerView, System.Text.Encoding.UTF8, "text/html")) <| ``Content-Type`` "text/html" } 24
  • 24. Frank– ShortUrl – POST the FORM let createShortUrl (request: HttpRequestMessage) = async { let! value = request.Content.AsyncReadAsMultipart() let longUrl = value.FirstDispositionNameOrDefault("longUrl") .ReadAsStringAsync().Result; let urlKey = longUrl.GetHashCode().ToString() urlStore.Add(urlKey, longUrl) let shortUrl = baseUri + "/" + longUrl.GetHashCode().ToString() return respond HttpStatusCode.OK (new StringContent(shortUrlCreatedView(shortUrl), System.Text.Encoding.UTF8, "text/html")) <| ``Content-Type`` "text/html" } 25
  • 25. Frank– ShortUrl - Redirecting let getShortUrl (request: HttpRequestMessage) = async { let urlKey = request .RequestUri .Segments.[request.RequestUri.Segments.Length - 1] let longUrl = urlStore.[urlKey] return respond HttpStatusCode.Redirect (new EmptyContent()) <| Location (new Uri(longUrl)) } let rootResource = routeResource "/" [ get urlShortenerForm <|> post createShortUrl ] let redirectReource = routeResource "/{shortUrl}" [ get getShortUrl ] let app = merge [ rootResource; redirectReource ] let config = new HttpSelfHostConfiguration(baseUri) config.Register app 26
  • 26. Why, again?  There are alternatives to ASP.NET  Know them!  Style matters  Tradeoffs, tradeoffs, tradeoffs 27
  • 27. What might you have learned? A taste of some altenatives  FubuMVC  OMIOMU  OpenRasta  Resources, Handlers, Codecs  Nancy  DSL  Frank  F# 28
  • 28. FubuMVC, OpenRasta, Nancy, Frank WHEN, WHAT, WHERE? 29