nancy & simple.data from prognet 11

14
Nancy & Simple.Data The Super-Duper-Happy Path

Upload: mark-rendle

Post on 26-May-2015

2.519 views

Category:

Technology


1 download

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

Nancy & Simple.Data

The Super-Duper-Happy Path

Page 2: Nancy & Simple.Data from ProgNet 11

Nancy• Inspired by Sinatra

o www.sinatrarb.com

• Low ceremony• High productivity

Page 3: Nancy & Simple.Data from ProgNet 11

Hello NancyDemo

Page 4: Nancy & Simple.Data from ProgNet 11

namespace NancyDemo{    public class MainModule : Nancy.NancyModule     {         public MainModule()         {             Get["/hi"] = _ => "Hello World!";         }     }}

Page 5: Nancy & Simple.Data from ProgNet 11

Simple.Data• Inspired by DataMapper & ActiveRecord

o datamapper.orgo rubyonrails.org

• Dynamic• Flexible

Page 6: Nancy & Simple.Data from ProgNet 11

Hello Simple.DataDemo

Page 7: Nancy & Simple.Data from ProgNet 11

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

Nancy, meetSimple.Data

Simple.Data, meet Nancy

Page 9: Nancy & Simple.Data from ProgNet 11

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

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

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

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
Page 14: Nancy & Simple.Data from ProgNet 11