building web apps with asp.net mvc and nosql

36
NoSQL, MVC, and Rich Forms by Michael Kennedy | @mkennedy | michaelckennedy.net DEVELOP MENTOR

Upload: michael-kennedy

Post on 10-May-2015

8.917 views

Category:

Technology


4 download

DESCRIPTION

This talk guides you through building modern web applications using ASP.NET MVC and MongoDB, one of the most popular NoSQL databases. You will learn some best practices for getting started with MVC. We’ll cover building rich-forms to accept user input. And if time permits, we might even add some client-side techniques using jQuery and MVC. All of this will be built upon the powerful non-relational database MongoDB. We will discuss the origins of the so-called NoSQL movement and why you might choose a non-relational database over SQL Server. You’ll also see our data access layer will be built using LINQ to MongoDB. Of course, you won’t be in for a night of PowerPoint. This talk is a series of interactive demos using Visual Studio 11, Windows 8, and C#.

TRANSCRIPT

Page 1: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

NoSQL, MVC, and Rich Formsby Michael Kennedy | @mkennedy | michaelckennedy.net

DEVELOPMENTOR

Page 2: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Introduction

* Introduction to NoSQL* Why NoSQL* CRUD with NoSQL databases* HTML Helpers* Model Binding* Unobtrusive Validation* Unified Client and Server Validation* View Models* JavaScript-Friendly Environment* Single-Page Applications (MVC 4)

DEVELOPMENTOR

Page 3: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

What's Your Experience with NoSQL?

DEVELOPMENTOR

Page 4: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

What is NoSQL?

The NoSQL movement is about re-evaluating the constraints and scalability of data storage systems in the light of the way modern web applications generate and consume data.

DEVELOPMENTOR

Page 5: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

What is NoSQL?

The NoSQL movement is about re-evaluating the constraints and scalability of data storage systems in the light of the way modern web applications generate and consume data.

DEVELOPMENTOR

Page 6: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Why NoSQL?

Axiom: A proposition whose truth is so evident that no reasoning or demonstration can make it plainer.

DEVELOPMENTOR

Starting from an RDBMS is virtually an axiom of software development.

When was the last time you consciously evaluated alternatives to an RDBMS?

Page 7: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Why NoSQL?

DEVELOPMENTOR

You can keep your ‘object / relational impedance mismatch’, thank you very much!

Page 8: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

MongoDB: A Powerful NoSQL Database

Combining the best features of document databases, key-values stores, and RDBMS.

DEVELOPMENTOR

http://www.mongodb.org/

Page 9: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

MongoDB:Just an Example

DEVELOPMENTOR

Page 10: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Is NoSQL only for Start-ups?

DEVELOPMENTOR

Page 11: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

DEVELOPMENTOR

Is NoSQL only for Start-ups?

Page 12: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Getting Started

DEVELOPMENTOR

Page 13: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

The Project: Amazoon

DEVELOPMENTOR

Page 14: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

The Data Model: Amazoon

DEVELOPMENTOR

Page 15: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Programming NoSQL

DEVELOPMENTOR

Find several provider libraries on NuGet, including the Official 10Gen C# driver.

Page 16: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Demo - Part 1: Amazoon Needs a Data Layer

Time to upgrade Amazoon: Amazoon needs to be able to do basic queries and inserts / updates.

DEVELOPMENTOR

Page 17: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Demo - Part 1: Amazoon Needs a Data Layer

DEVELOPMENTOR

Page 18: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

The GET, POST, Redirect Pattern

DEVELOPMENTOR

GET/book/edit/42

POST/book/edit/42 + changes

HTTP 302 -

Red

irect

/book

/show

/42

update data

Edit data locally

Page 19: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

The GET, POST, Redirect Pattern

DEVELOPMENTOR

1

2

3

4

Page 20: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Demo - Part 2: Forms, Model Binding, and HTML Helpers

"Pure" HTML forms are valid but not optimal in MVC. Make use of @Html extensions. Html.BeginForm(), Html.TextBoxFor(), etc. Usually, this is far easier with Model Binding.

DEVELOPMENTOR

Page 21: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Demo - Part 2: Forms, Model Binding, and HTML Helpers

Time to upgrade Amazoon: Amazoon needs an admin section where we can create categories and books.

DEVELOPMENTOR

Page 22: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Demo - Part 2: Forms, Model Binding, and HTML Helpers

DEVELOPMENTOR

Page 23: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Demo - Part 2: Forms, Model Binding, and HTML Helpers

Well, that mostly worked. But it was clunky on several levels. * ViewBag is untyped and non-discoverable* Many parameters "capture" the form values* What about validation?

DEVELOPMENTOR

Page 24: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Demo - Part 3: View Models and Validation

Now that we got the site working with the new features, let's clean it up. * View Models (Model Binding at the next level)* Validation (is easier with View Models)

DEVELOPMENTOR

Page 25: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Demo - Part 3: View Models and Validation

DEVELOPMENTOR

Page 26: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Demo - Part 3: View Models and Validation

DEVELOPMENTOR

Page 27: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Demo - Part 4: Adding Real Usability with Client-Side Code

Time to upgrade Amazoon (again): Comments and discussions around books. These are already in place, but the full-page refresh is not usable on these potentially large pages.

DEVELOPMENTOR

Page 28: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Demo - Part 4: Adding Real Usability with Client-Side Code

DEVELOPMENTOR

Page 29: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Demo - Part 4: Adding Real Usability with Client-Side Code

DEVELOPMENTOR

Page 30: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Fully Client-Side MVC Applications

MVC 4 introduces the concept of Single-Page Applications (think gmail). These combine many technologies: * MVC and ASP.NET Web API* Knockout.js* Upshot.js* HTML5

DEVELOPMENTOR

Page 31: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Fully Client-Side MVC Applications

DEVELOPMENTORhttp://bit.ly/sanderson-spa

Page 32: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

I Want My Management Tools

DEVELOPMENTOR

Page 33: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Scaling-Out is Easier With NoSQL

So you say it's fast, eh? What do you mean by fast?

DEVELOPMENTOR

Dropping ACID with MongoDB on USTREAM

Page 34: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Conclusion (MVC)

Just some of the features we've explored in MVC:

* HTML Helpers* Model Binding* Unobtrusive Validation* Unified Client and Server Validation* View Models* JavaScript-Friendly Environment* Single-Page Applications (MVC 4)

DEVELOPMENTOR

Page 35: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

Conclusion (NoSQL)

DEVELOPMENTOR

Just some of the features we've explored in NoSQL:

* Your database is a choice you make for each project* NoSQL => Non-relational* Strongly supports horizontal scale-out* LINQ works great

Page 36: BUILDING WEB APPS WITH ASP.NET MVC AND NOSQL

More from DevelopMentor

DEVELOPMENTOR

* Guerrilla .NET (May 7th in Boston) * Essential ASP.NET MVC * JavaScript and jQuery * HTML5 * + lots more @mkennedy@DevelopMentor_

http://www.develop.com/training-courses/web