SlideShare a Scribd company logo
Click to edit Master title style
• Click to edit Master text styles
      – Second level
             • Third level
                – Fourth level
                    » Fifth level



                    ANUG December 2011




20-12-2011                                  1
Agenda

 Who Am I?

   Super Duper Happy Path
   NancyModule
   Nancy.Hosting
   Nancy.ViewEngines
   Nancy.Bootstrapper
   Nancy.Authentication
   Nancy.Testing

 Why use Nancy?
Super Duper Happy Path




3
Super Duper Happy Path

     Lightweight
       Write less
       Sensible defaults
       No non sense
     Dynamic
       Best effort – very best
     Readable!!!!
     Testable!!!!


4
Super Duper Happy Path


                             Web




            Inventory
                         Domain      Data access
                          Model




                        Accounting

5
Super Duper Happy Path




     Fully composable
     Dependency Injection
     Easy to isolate




6
Super Duper Happy Path

     Runs anywhere
       Windows
         » IIS
         » Windows Service
         » .exe
       Linux + Mono
         » ASP.NET
         » Kayak
         » executables
       Azure
       AppHarbor

7
Click to edit Master title style
• Click to edit Master text styles
      – Second level
             • Third level
                – Fourth level
                    » Fifth level
             Show me the code!



20-12-2011                                  8
Hello World
         Click to edit Master title style
• Click to edit Master text styles
      – Second level
             • Third level
                – Fourth level
                    » Fifth level




20-12-2011                                  9
NancyModule

 Where your Nancy experience starts
 Organizes your routes
  public class MainModule : NancyModule
  {
         public MainModule()
         {
             Get["/"] = _ => "Hello from root";
         }
    }

  public class SubModule : NancyModule
   {
         public SubModule() : base("subpath")
         {
             Get["/"] = _ => "Hello from subpath";
         }
   }
NancyModule

 Defines which verbs you accepts


  public class MainModule : NancyModule
  {
         public MainModule()
         {
             Get["/"] = _ => "Hello from root";
             Post["/”] = _ => DoPost(Request.Form.my_value)
             Delete["/{id}”] = p => Delete(p.id);
             Put["/”] = _ => …
             Patch["/”] = _ => DoPut(Request.my_data)
         }
    }
NancyModule

 Allows to setup before and after


  public class MainModule : NancyModule
  {
         public MainModule()
         {
             Before += context => ... ;
             After += context => ... ;
           }
    }
Nancy.Hosting


                Your Application


                     Nancy


                 Nancy.Hosting


                       …
Nancy.Hosting

 Usage:
   > Install-Package Nancy.Hosting.*


 Hosts:
   ASP.NET
   WCF
   Self
   OWIN
Nancy.Viewengines

 Install:
    > Install-Package Nancy.Viewengines.*


 View engines:
    Razor
    Spark
    NDjango
    DotLiquid


 Out-of-the-box:
    Super Simple View Engine
Nancy.Viewengines




     public class MainModule : NancyModule
     {
            public MainModule()
            {
                Get["/"] = _ => View[”home.cshtml”];
                Get["/sayhello"] = _ => View[”say”, ”hello”];
            }
       }




16
Nancy.Bootstrapper

      INancyBootstrapper
         2 methods


      DefaultNancyBootstrapper
         18 overrideables
         Container configuration
         Pipeline setup
         Override Nancy defaults


      NuGets for 5 IoC/DI containers

17
Nancy.Bootstrapper

      public class Bootstrapper : DefaultNancyBootstrapper
      {
          protected override void
               ApplicationStartup(TinyIoC.TinyIoCContainer container,
                                  IPipelines pipelines)
          {
              base.ApplicationStartup(container, pipelines);
              pipelines.BeforeRequest +=
                  context =>
                      context
                         .Request.Headers
                         .AcceptLanguage
                         .Contains("Danish") ? null : "Only Danish";
               pipelines.AfterRequest +=
                   context =>
                       AddToCache(context.Request.Path,
                                  context.Response.Contents);
          }
      }
18
Nancy.Authentication

      Usage:
        > Install-Package Nancy.Authentication.*


      Authentication types:
        Basic
        Forms




19
Nancy.Authentication



       public class SecureModule : NancyModule
       {
           public SecureModule() : base("/secure”)
           {
               this.RequiresAuthentication();
               Get["/"] = x => View["secure.cshtml”];
           }
        }




20
Nancy.Authentication


       public class FormsAuthBootstrapper : DefaultNancyBootstrapper
       {
           protected override void RequestStartup(
               TinyIoCContainer requestContainer,
               IPipelines pipelines,
               NancyContext context)
           {
                var formsAuthConf =
                     new FormsAuthenticationConfiguration()
                     {
                         RedirectUrl = "~/login”,
                         UserMapper =
                             requestContainer.Resolve<IUserMapper>()
                     };
               FormsAuthentication.Enable(pipelines, formsAuthConf);
           }
       }




21
Nancy.Testing




       Will be demoed later …




22
Nancy

      Super Duper Happy Path
      NancyModule
      Nancy.Hosting
      Nancy.ViewEngines
      Nancy.Bootstrapper
      Nancy.Authentication
      Nancy.Testing


       …And we’re only at v 0.9
23
Why Nancy

      Close to http
      Very, very readable code
      Very explicit routing
      Embraces modularity
      Embraces IoC/DI
      Embraces testing
      Embraces JSON
      Runs anywhere


24
Resources

      www.nancyfx.org
      https://groups.google.com/forum/#!forum/nancy-web-framework
      www.twitter.com/nancyfx
      http://horsdal.blogspot.com/search/label/NancyFx




25
Click to edit Master title style
 • Click to edit Master text styles
       – Second level
        • Third level
Christian Horsdal level
            – Fourth
Twitter: @chr_horsdal
                » Fifth level
Blog: horsdal.blogspot.com
email: chg@mjolner.dk


Mjølner Informatics A/S   Tlf: +45 70 27 43 43   info@mjolner.dk
Finlandsgade 10           CVR: 1257 8970         www.mjolner.dk
DK- 8200 Aarhus N


 20-12-2011                                                        27

More Related Content

What's hot (20)

PDF
Supercharging Content Delivery with Varnish
Samantha Quiñones
 
KEY
Introduction to NodeJS with LOLCats
Derek Anderson
 
PDF
SVN essentials
Bedis ElAchèche
 
PDF
Introduction to Systems Management with SaltStack
Craig Sebenik
 
PDF
Node.js 101 with Rami Sayar
FITC
 
PDF
Apache Camel in the belly of the Docker whale
Henryk Konsek
 
PDF
vert.x 3.1 - be reactive on the JVM but not only in Java
Clément Escoffier
 
PDF
Introduction to Node.js
Richard Lee
 
PDF
Containers > VMs
David Timothy Strauss
 
PDF
Basic Understanding and Implement of Node.js
Gary Yeh
 
PPTX
5. react native-package
Govind Prasad Gupta
 
PDF
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
PDF
CP3108B (Mozilla) Sharing Session on Add-on SDK
Mifeng
 
PDF
OpenNebula, the foreman and CentOS play nice, too
inovex GmbH
 
KEY
Dcjq node.js presentation
async_io
 
ODP
WebSockets with PHP: Mission impossible
Yoan-Alexander Grigorov
 
PDF
A user's perspective on SaltStack and other configuration management tools
SaltStack
 
PDF
Porting Flashblock to Jetpack Platform (draft)
Thomas Bassetto
 
PPT
Introduction to node.js aka NodeJS
JITENDRA KUMAR PATEL
 
PDF
Making MySQL Administration a Breeze - A Look Into a MySQL DBA's Toolchest
Lenz Grimmer
 
Supercharging Content Delivery with Varnish
Samantha Quiñones
 
Introduction to NodeJS with LOLCats
Derek Anderson
 
SVN essentials
Bedis ElAchèche
 
Introduction to Systems Management with SaltStack
Craig Sebenik
 
Node.js 101 with Rami Sayar
FITC
 
Apache Camel in the belly of the Docker whale
Henryk Konsek
 
vert.x 3.1 - be reactive on the JVM but not only in Java
Clément Escoffier
 
Introduction to Node.js
Richard Lee
 
Containers > VMs
David Timothy Strauss
 
Basic Understanding and Implement of Node.js
Gary Yeh
 
5. react native-package
Govind Prasad Gupta
 
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
CP3108B (Mozilla) Sharing Session on Add-on SDK
Mifeng
 
OpenNebula, the foreman and CentOS play nice, too
inovex GmbH
 
Dcjq node.js presentation
async_io
 
WebSockets with PHP: Mission impossible
Yoan-Alexander Grigorov
 
A user's perspective on SaltStack and other configuration management tools
SaltStack
 
Porting Flashblock to Jetpack Platform (draft)
Thomas Bassetto
 
Introduction to node.js aka NodeJS
JITENDRA KUMAR PATEL
 
Making MySQL Administration a Breeze - A Look Into a MySQL DBA's Toolchest
Lenz Grimmer
 

Similar to Nancy - A Lightweight .NET Web Framework (20)

PPTX
A Minimalist’s Attempt at Building a Distributed Application
David Hoerster
 
PPTX
Nancy + rest mow2012
Christian Horsdal
 
PDF
Syllabus PS03CINT05 detailing
OPENLANE
 
PDF
Mini-Training: NancyFX
Betclic Everest Group Tech Team
 
PPTX
Asp.Net MVC3 - Basics
Saravanan Subburayal
 
PPTX
ASP.NET MVC as the next step in web development
Volodymyr Voytyshyn
 
PPTX
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
Chalermpon Areepong
 
PPTX
Lightweight Approach to Building Web APIs with .NET
Christian Horsdal
 
PPTX
Intro to .NET for Government Developers
Frank La Vigne
 
PPTX
MVC 4
Vasilios Kuznos
 
PDF
Dot net training bangalore
IGEEKS TECHNOLOGIES
 
PPTX
Day6
madamewoolf
 
PPTX
Versulo (2)
Mircea Chirea
 
PPTX
Women Who Code, Ground Floor
Katie Weiss
 
PPTX
Introduction to .NET with C# @ university of wayamba
Prageeth Sandakalum
 
PDF
.net
ranjanbrcm
 
PPTX
How to get full power from WebApi
Raffaele Rialdi
 
PDF
Stucorner dot-net-training-syllabus
STUCORNER technology
 
PPT
Building+restful+webservice
lonegunman
 
PPTX
Day7
madamewoolf
 
A Minimalist’s Attempt at Building a Distributed Application
David Hoerster
 
Nancy + rest mow2012
Christian Horsdal
 
Syllabus PS03CINT05 detailing
OPENLANE
 
Mini-Training: NancyFX
Betclic Everest Group Tech Team
 
Asp.Net MVC3 - Basics
Saravanan Subburayal
 
ASP.NET MVC as the next step in web development
Volodymyr Voytyshyn
 
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
Chalermpon Areepong
 
Lightweight Approach to Building Web APIs with .NET
Christian Horsdal
 
Intro to .NET for Government Developers
Frank La Vigne
 
Dot net training bangalore
IGEEKS TECHNOLOGIES
 
Versulo (2)
Mircea Chirea
 
Women Who Code, Ground Floor
Katie Weiss
 
Introduction to .NET with C# @ university of wayamba
Prageeth Sandakalum
 
How to get full power from WebApi
Raffaele Rialdi
 
Stucorner dot-net-training-syllabus
STUCORNER technology
 
Building+restful+webservice
lonegunman
 
Ad

More from Christian Horsdal (10)

PPTX
Testing microservices.ANUG.20230111.pptx
Christian Horsdal
 
PDF
Scoping microservices.20190917
Christian Horsdal
 
PPTX
Event sourcing anug 20190227
Christian Horsdal
 
PPTX
Consolidating services with middleware - NDC London 2017
Christian Horsdal
 
PPTX
Intro to.net core 20170111
Christian Horsdal
 
PPTX
Middleware webnextconf - 20152609
Christian Horsdal
 
PPTX
ASP.NET vNext ANUG 20140817
Christian Horsdal
 
PPTX
Four .NET Web Frameworks in Less Than an Hour
Christian Horsdal
 
PPTX
DCI ANUG - 24th November 2010
Christian Horsdal
 
PPTX
DCI - ANUG 24th November 2010
Christian Horsdal
 
Testing microservices.ANUG.20230111.pptx
Christian Horsdal
 
Scoping microservices.20190917
Christian Horsdal
 
Event sourcing anug 20190227
Christian Horsdal
 
Consolidating services with middleware - NDC London 2017
Christian Horsdal
 
Intro to.net core 20170111
Christian Horsdal
 
Middleware webnextconf - 20152609
Christian Horsdal
 
ASP.NET vNext ANUG 20140817
Christian Horsdal
 
Four .NET Web Frameworks in Less Than an Hour
Christian Horsdal
 
DCI ANUG - 24th November 2010
Christian Horsdal
 
DCI - ANUG 24th November 2010
Christian Horsdal
 
Ad

Recently uploaded (20)

PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Français Patch Tuesday - Juillet
Ivanti
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Top Managed Service Providers in Los Angeles
Captain IT
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Français Patch Tuesday - Juillet
Ivanti
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 

Nancy - A Lightweight .NET Web Framework

  • 1. Click to edit Master title style • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level ANUG December 2011 20-12-2011 1
  • 2. Agenda  Who Am I?  Super Duper Happy Path  NancyModule  Nancy.Hosting  Nancy.ViewEngines  Nancy.Bootstrapper  Nancy.Authentication  Nancy.Testing  Why use Nancy?
  • 4. Super Duper Happy Path  Lightweight  Write less  Sensible defaults  No non sense  Dynamic  Best effort – very best  Readable!!!!  Testable!!!! 4
  • 5. Super Duper Happy Path Web Inventory Domain Data access Model Accounting 5
  • 6. Super Duper Happy Path  Fully composable  Dependency Injection  Easy to isolate 6
  • 7. Super Duper Happy Path  Runs anywhere  Windows » IIS » Windows Service » .exe  Linux + Mono » ASP.NET » Kayak » executables  Azure  AppHarbor 7
  • 8. Click to edit Master title style • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Show me the code! 20-12-2011 8
  • 9. Hello World Click to edit Master title style • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level 20-12-2011 9
  • 10. NancyModule  Where your Nancy experience starts  Organizes your routes public class MainModule : NancyModule { public MainModule() { Get["/"] = _ => "Hello from root"; } } public class SubModule : NancyModule { public SubModule() : base("subpath") { Get["/"] = _ => "Hello from subpath"; } }
  • 11. NancyModule  Defines which verbs you accepts public class MainModule : NancyModule { public MainModule() { Get["/"] = _ => "Hello from root"; Post["/”] = _ => DoPost(Request.Form.my_value) Delete["/{id}”] = p => Delete(p.id); Put["/”] = _ => … Patch["/”] = _ => DoPut(Request.my_data) } }
  • 12. NancyModule  Allows to setup before and after public class MainModule : NancyModule { public MainModule() { Before += context => ... ; After += context => ... ; } }
  • 13. Nancy.Hosting Your Application Nancy Nancy.Hosting …
  • 14. Nancy.Hosting  Usage:  > Install-Package Nancy.Hosting.*  Hosts:  ASP.NET  WCF  Self  OWIN
  • 15. Nancy.Viewengines  Install:  > Install-Package Nancy.Viewengines.*  View engines:  Razor  Spark  NDjango  DotLiquid  Out-of-the-box:  Super Simple View Engine
  • 16. Nancy.Viewengines public class MainModule : NancyModule { public MainModule() { Get["/"] = _ => View[”home.cshtml”]; Get["/sayhello"] = _ => View[”say”, ”hello”]; } } 16
  • 17. Nancy.Bootstrapper  INancyBootstrapper  2 methods  DefaultNancyBootstrapper  18 overrideables  Container configuration  Pipeline setup  Override Nancy defaults  NuGets for 5 IoC/DI containers 17
  • 18. Nancy.Bootstrapper public class Bootstrapper : DefaultNancyBootstrapper { protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipelines) { base.ApplicationStartup(container, pipelines); pipelines.BeforeRequest += context => context .Request.Headers .AcceptLanguage .Contains("Danish") ? null : "Only Danish"; pipelines.AfterRequest += context => AddToCache(context.Request.Path, context.Response.Contents); } } 18
  • 19. Nancy.Authentication  Usage:  > Install-Package Nancy.Authentication.*  Authentication types:  Basic  Forms 19
  • 20. Nancy.Authentication public class SecureModule : NancyModule { public SecureModule() : base("/secure”) { this.RequiresAuthentication(); Get["/"] = x => View["secure.cshtml”]; } } 20
  • 21. Nancy.Authentication public class FormsAuthBootstrapper : DefaultNancyBootstrapper { protected override void RequestStartup( TinyIoCContainer requestContainer, IPipelines pipelines, NancyContext context) { var formsAuthConf = new FormsAuthenticationConfiguration() { RedirectUrl = "~/login”, UserMapper = requestContainer.Resolve<IUserMapper>() }; FormsAuthentication.Enable(pipelines, formsAuthConf); } } 21
  • 22. Nancy.Testing Will be demoed later … 22
  • 23. Nancy  Super Duper Happy Path  NancyModule  Nancy.Hosting  Nancy.ViewEngines  Nancy.Bootstrapper  Nancy.Authentication  Nancy.Testing …And we’re only at v 0.9 23
  • 24. Why Nancy  Close to http  Very, very readable code  Very explicit routing  Embraces modularity  Embraces IoC/DI  Embraces testing  Embraces JSON  Runs anywhere 24
  • 25. Resources  www.nancyfx.org  https://groups.google.com/forum/#!forum/nancy-web-framework  www.twitter.com/nancyfx  http://horsdal.blogspot.com/search/label/NancyFx 25
  • 26. Click to edit Master title style • Click to edit Master text styles – Second level • Third level Christian Horsdal level – Fourth Twitter: @chr_horsdal » Fifth level Blog: horsdal.blogspot.com email: [email protected] Mjølner Informatics A/S Tlf: +45 70 27 43 43 [email protected] Finlandsgade 10 CVR: 1257 8970 www.mjolner.dk DK- 8200 Aarhus N 20-12-2011 27