nancy & simple.data from prognet 11
DESCRIPTION
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. :)TRANSCRIPT
![Page 1: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/1.jpg)
Nancy & Simple.Data
The Super-Duper-Happy Path
![Page 2: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/2.jpg)
Nancy• Inspired by Sinatra
o www.sinatrarb.com
• Low ceremony• High productivity
![Page 3: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/3.jpg)
Hello NancyDemo
![Page 4: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/4.jpg)
namespace NancyDemo{ public class MainModule : Nancy.NancyModule { public MainModule() { Get["/hi"] = _ => "Hello World!"; } }}
![Page 5: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/5.jpg)
Simple.Data• Inspired by DataMapper & ActiveRecord
o datamapper.orgo rubyonrails.org
• Dynamic• Flexible
![Page 6: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/6.jpg)
Hello Simple.DataDemo
![Page 7: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/7.jpg)
namespace Hello{ class Program { static void Main() { var db = Simple.Data.Database.Open(); var hello = db.Hello.FindById(1); Console.WriteLine("{0}, {1}!", hello.Greeting, hello.Subject); } }}
![Page 8: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/8.jpg)
Nancy, meetSimple.Data
Simple.Data, meet Nancy
![Page 9: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/9.jpg)
public class MainModule : NancyModule{ private readonly dynamic _db = Database.OpenNamedConnection("ProgNet");
public MainModule() { Get["/"] = _ => { var scrawls = _db.Graffiti.All().OrderByAddedDescending(); return View["index", scrawls]; };
Post["/"] = _ => { _db.Graffiti.Insert(Text: Request.Form.Text); return new RedirectResponse("/"); }; }}
![Page 10: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/10.jpg)
Authentication• Nancy.Authentication.Basic
o Basic HTTP authentication
• Nancy.Authentication.Formso Proper authenticationo Also works as basis for Social login (e.g. Facebook, Twitter)
![Page 11: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/11.jpg)
public class MyBootstrapper : DefaultNancyBootstrapper{ protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container) { base.InitialiseInternal(container);
FormsAuthentication.Enable( this, new FormsAuthenticationConfiguration { RedirectUrl = "~/login", UsernameMapper = container.Resolve<IUsernameMapper>() }); }}
public class MyModule : NancyModule{ public MyModule() : base("/secure") { this.RequiresAuthentication();
Get["/"] = _ => "Secure!"; }}
![Page 12: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/12.jpg)
Exercise• A Super-Duper-Happy ToDo app• Download: SQL CE DB and EncryptionHelper:
o http://bit.ly/ProgNet-NSD
• Database schema:
• Users • ToDos
• Id: Guid (PK)• Email: nvarchar(128)• EncryptedPassword:
binary(32)
• Salt] binary(32)
• Id Guid (PK)• UserId Guid (FK)• Text nvarchar(1024)• Added] datetime
DEFAULT GETDATE()• Done datetime
![Page 13: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/13.jpg)
![Page 14: Nancy & Simple.Data from ProgNet 11](https://reader037.vdocuments.mx/reader037/viewer/2022091118/55644808d8b42a682d8b4902/html5/thumbnails/14.jpg)