Nancy & Simple.Data from ProgNet 11

2,806 views
2,656 views

Published on

These are the slides from the tutorial I gave at Skills Matter's Progressive .NET Tutorials 2011.

Feel free to use content from these slides in your own presentations, but please mention the source in your talk. :)

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,806
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Nancy & Simple.Data from ProgNet 11

  1. 1. Nancy & Simple.Data<br />The Super-Duper-Happy Path<br />
  2. 2. Nancy<br />Inspired by Sinatra<br />www.sinatrarb.com<br />Low ceremony<br />High productivity<br />
  3. 3. Hello Nancy<br />Demo<br />
  4. 4. namespace NancyDemo<br />{<br />    public class MainModule : Nancy.NancyModule<br />     {<br />         public MainModule()<br />         {<br />             Get["/hi"] = _ => "Hello World!";<br />         }<br />     }<br />}<br />
  5. 5. Simple.Data<br />Inspired by DataMapper & ActiveRecord<br />datamapper.org<br />rubyonrails.org<br />Dynamic<br />Flexible<br />
  6. 6. Hello Simple.Data<br />Demo<br />
  7. 7. namespace Hello<br />{<br />classProgram<br /> {<br /> staticvoid Main()<br /> {<br />vardb = Simple.Data.Database.Open();<br />var hello = db.Hello.FindById(1);<br />Console.WriteLine("{0}, {1}!",<br />hello.Greeting, hello.Subject);<br /> }<br /> }<br />}<br />
  8. 8. Nancy, meetSimple.Data<br />Simple.Data, meet Nancy<br />
  9. 9. publicclassMainModule : NancyModule<br />{<br />privatereadonlydynamic _db = Database.OpenNamedConnection("ProgNet");<br />publicMainModule()<br />{<br />Get["/"] =<br />_ =><br />{<br />var scrawls = _db.Graffiti.All().OrderByAddedDescending();<br />returnView["index", scrawls];<br />};<br />Post["/"] =<br />_ =><br />{<br />_db.Graffiti.Insert(Text: Request.Form.Text);<br />returnnewRedirectResponse("/");<br />};<br />}<br />}<br />
  10. 10. Authentication<br />Nancy.Authentication.Basic<br />Basic HTTP authentication<br />Nancy.Authentication.Forms<br />Proper authentication<br />Also works as basis for Social login (e.g. Facebook, Twitter)<br />
  11. 11. publicclassMyBootstrapper: DefaultNancyBootstrapper<br />{<br />protectedoverridevoidInitialiseInternal(TinyIoC.TinyIoCContainer container)<br /> {<br />base.InitialiseInternal(container);<br />FormsAuthentication.Enable(<br />this, <br />newFormsAuthenticationConfiguration<br /> {<br />RedirectUrl = "~/login",<br />UsernameMapper = container.Resolve<IUsernameMapper>()<br /> });<br /> }<br />}<br />publicclassMyModule: NancyModule<br />{<br /> publicMyModule() : base("/secure")<br /> {<br />this.RequiresAuthentication();<br /> Get["/"] = _ => "Secure!";<br /> }<br />}<br />
  12. 12. Exercise<br />A Super-Duper-Happy ToDo app<br />Download: SQL CE DB and EncryptionHelper:<br />http://bit.ly/ProgNet-NSD<br />Database schema:<br />Users<br />ToDos<br />Id: Guid (PK)<br />Email: nvarchar(128)<br />EncryptedPassword: binary(32)<br />Salt] binary(32)<br />Id Guid (PK)<br />UserId Guid (FK)<br />Text nvarchar(1024)<br />Added] datetime DEFAULT GETDATE()<br />Done datetime<br />

×