nancy - a lightweight .net web framework
TRANSCRIPT
![Page 1: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/1.jpg)
Click to edit Master title style
• Click to edit Master text styles– Second level• Third level
– Fourth level» Fifth level
20-12-2011 1
ANUG December 2011
![Page 2: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/2.jpg)
Who Am I?
Super Duper Happy Path
NancyModule
Nancy.Hosting
Nancy.ViewEngines
Nancy.Bootstrapper
Nancy.Authentication
Nancy.Testing
Why use Nancy?
Agenda
![Page 3: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/3.jpg)
3
Super Duper Happy Path
![Page 4: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/4.jpg)
4
LightweightWrite less
Sensible defaults
No non sense
DynamicBest effort – very best
Readable!!!!
Testable!!!!
Super Duper Happy Path
![Page 5: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/5.jpg)
5
Domain Model
Web
Data access
Accounting
Inventory
Super Duper Happy Path
![Page 6: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/6.jpg)
6
Fully composable
Dependency Injection
Easy to isolate
Super Duper Happy Path
![Page 7: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/7.jpg)
7
Runs anywhereWindows
» IIS» Windows Service» .exe
Linux + Mono
» ASP.NET» Kayak» executables
Azure
AppHarbor
Super Duper Happy Path
![Page 8: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/8.jpg)
Click to edit Master title style
• Click to edit Master text styles– Second level• Third level
– Fourth level» Fifth level
20-12-2011 8
Show me the code!
![Page 9: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/9.jpg)
Click to edit Master title style
• Click to edit Master text styles– Second level• Third level
– Fourth level» Fifth level
20-12-2011 9
Hello World
![Page 10: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/10.jpg)
Where your Nancy experience starts
Organizes your routes
NancyModule
public class MainModule : NancyModule { public MainModule() { Get["/"] = _ => "Hello from root"; } } public class SubModule : NancyModule { public SubModule() : base("subpath") { Get["/"] = _ => "Hello from subpath"; } }
![Page 11: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/11.jpg)
Defines which verbs you accepts
NancyModule
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) } }
![Page 12: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/12.jpg)
Allows to setup before and after
NancyModule
public class MainModule : NancyModule { public MainModule() { Before += context => ... ; After += context => ... ; } }
![Page 13: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/13.jpg)
…
Nancy.Hosting
Nancy
Your Application
Nancy.Hosting
![Page 14: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/14.jpg)
Usage:> Install-Package Nancy.Hosting.*
Hosts:ASP.NET
WCF
Self
OWIN
Nancy.Hosting
![Page 15: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/15.jpg)
Install: > Install-Package Nancy.Viewengines.*
View engines: Razor
Spark
NDjango
DotLiquid
Out-of-the-box: Super Simple View Engine
Nancy.Viewengines
![Page 16: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/16.jpg)
16
public class MainModule : NancyModule { public MainModule() { Get["/"] = _ => View[”home.cshtml”]; Get["/sayhello"] = _ => View[”say”, ”hello”]; } }
Nancy.Viewengines
![Page 17: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/17.jpg)
17
INancyBootstrapper
2 methods
DefaultNancyBootstrapper
18 overrideables
Container configuration
Pipeline setup
Override Nancy defaults
NuGets for 5 IoC/DI containers
Nancy.Bootstrapper
![Page 18: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/18.jpg)
18
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); }}
Nancy.Bootstrapper
![Page 19: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/19.jpg)
19
Usage:> Install-Package Nancy.Authentication.*
Authentication types:Basic
Forms
Nancy.Authentication
![Page 20: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/20.jpg)
20
public class SecureModule : NancyModule{ public SecureModule() : base("/secure”) { this.RequiresAuthentication(); Get["/"] = x => View["secure.cshtml”]; } }
Nancy.Authentication
![Page 21: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/21.jpg)
21
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); }}
Nancy.Authentication
![Page 22: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/22.jpg)
22
Will be demoed later …
Nancy.Testing
![Page 23: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/23.jpg)
23
Super Duper Happy Path
NancyModule
Nancy.Hosting
Nancy.ViewEngines
Nancy.Bootstrapper
Nancy.Authentication
Nancy.Testing
…And we’re only at v 0.9
Nancy
![Page 24: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/24.jpg)
24
Close to http
Very, very readable code
Very explicit routing
Embraces modularity
Embraces IoC/DI
Embraces testing
Embraces JSON
Runs anywhere
Why Nancy
![Page 25: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/25.jpg)
25
www.nancyfx.org
https://groups.google.com/forum/#!forum/nancy-web-framework
www.twitter.com/nancyfx
http://horsdal.blogspot.com/search/label/NancyFx
Resources
![Page 26: Nancy - A Lightweight .NET Web Framework](https://reader036.vdocuments.mx/reader036/viewer/2022062307/5560c6e0d8b42af1028b47af/html5/thumbnails/26.jpg)
Click to edit Master title style
• Click to edit Master text styles– Second level• Third level
– Fourth level» Fifth level
20-12-2011 27
Mjølner Informatics A/SFinlandsgade 10DK- 8200 Aarhus N
Tlf: +45 70 27 43 43CVR: 1257 8970
Christian HorsdalTwitter: @chr_horsdalBlog: horsdal.blogspot.comemail: [email protected]