Nancy - A Lightweight .NET Web Framework

4,557 views
4,410 views

Published on

Published in: Technology, Education
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
4,557
On SlideShare
0
From Embeds
0
Number of Embeds
1,507
Actions
Shares
0
Downloads
23
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Nancy - A Lightweight .NET Web Framework

  1. 1. Click to edit Master title style• Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level ANUG December 201120-12-2011 1
  2. 2. Agenda Who Am I? Super Duper Happy Path NancyModule Nancy.Hosting Nancy.ViewEngines Nancy.Bootstrapper Nancy.Authentication Nancy.Testing Why use Nancy?
  3. 3. Super Duper Happy Path3
  4. 4. Super Duper Happy Path  Lightweight  Write less  Sensible defaults  No non sense  Dynamic  Best effort – very best  Readable!!!!  Testable!!!!4
  5. 5. Super Duper Happy Path Web Inventory Domain Data access Model Accounting5
  6. 6. Super Duper Happy Path  Fully composable  Dependency Injection  Easy to isolate6
  7. 7. Super Duper Happy Path  Runs anywhere  Windows » IIS » Windows Service » .exe  Linux + Mono » ASP.NET » Kayak » executables  Azure  AppHarbor7
  8. 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. 9. Hello World Click to edit Master title style• Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level20-12-2011 9
  10. 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. 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. 12. NancyModule Allows to setup before and after public class MainModule : NancyModule { public MainModule() { Before += context => ... ; After += context => ... ; } }
  13. 13. Nancy.Hosting Your Application Nancy Nancy.Hosting …
  14. 14. Nancy.Hosting Usage:  > Install-Package Nancy.Hosting.* Hosts:  ASP.NET  WCF  Self  OWIN
  15. 15. Nancy.Viewengines Install:  > Install-Package Nancy.Viewengines.* View engines:  Razor  Spark  NDjango  DotLiquid Out-of-the-box:  Super Simple View Engine
  16. 16. Nancy.Viewengines public class MainModule : NancyModule { public MainModule() { Get["/"] = _ => View[”home.cshtml”]; Get["/sayhello"] = _ => View[”say”, ”hello”]; } }16
  17. 17. Nancy.Bootstrapper  INancyBootstrapper  2 methods  DefaultNancyBootstrapper  18 overrideables  Container configuration  Pipeline setup  Override Nancy defaults  NuGets for 5 IoC/DI containers17
  18. 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. 19. Nancy.Authentication  Usage:  > Install-Package Nancy.Authentication.*  Authentication types:  Basic  Forms19
  20. 20. Nancy.Authentication public class SecureModule : NancyModule { public SecureModule() : base("/secure”) { this.RequiresAuthentication(); Get["/"] = x => View["secure.cshtml”]; } }20
  21. 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. 22. Nancy.Testing Will be demoed later …22
  23. 23. Nancy  Super Duper Happy Path  NancyModule  Nancy.Hosting  Nancy.ViewEngines  Nancy.Bootstrapper  Nancy.Authentication  Nancy.Testing …And we’re only at v 0.923
  24. 24. Why Nancy  Close to http  Very, very readable code  Very explicit routing  Embraces modularity  Embraces IoC/DI  Embraces testing  Embraces JSON  Runs anywhere24
  25. 25. Resources  www.nancyfx.org  https://groups.google.com/forum/#!forum/nancy-web-framework  www.twitter.com/nancyfx  http://horsdal.blogspot.com/search/label/NancyFx25
  26. 26. Click to edit Master title style • Click to edit Master text styles – Second level • Third levelChristian Horsdal level – FourthTwitter: @chr_horsdal » Fifth levelBlog: horsdal.blogspot.comemail: chg@mjolner.dkMjølner Informatics A/S Tlf: +45 70 27 43 43 info@mjolner.dkFinlandsgade 10 CVR: 1257 8970 www.mjolner.dkDK- 8200 Aarhus N 20-12-2011 27

×