Style A ReadMe - Bitbucket

chulavistajuniorΚινητά – Ασύρματες Τεχνολογίες

10 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

108 εμφανίσεις

Last saved:
12/10/2013

Author

/
Title

1

Chapter author name:

©Manning Publications Co.
Please post comments or corrections to

the
Author Online forum:

http://www.manning
-
sandbox.com/forum.jspa?forumID=XYZ

Appendix A

ASP.NET MVC 4

This appendix covers



What

s new in ASP.NET MVC 4



Known details about upcoming features



Where to watch for more information

While this book was
being
written from experiences
with ASP.NET MVC 3 in real and
substantia
l projects, the Microsoft product
-
development juggernaut marches on. The
ASP.NET product team has revealed a few preliminary ideas about the upcoming ASP.NET
MVC 4. And while they have only released half
-
finished preview iterations of the new
framework, w
e thought it would be worth mentioning a few of their plans
,

even if they are
subject to change.

The themes of
ASP.NET MVC 4 will include an improved experience developing for mobile
devices and other emerging platforms. Razor is still new

ASP.NET M
VC 3 included the first
iteration of the syntax, and we

ll see improvements and enhancements there. And NuGet will
be exploited even further to allow developers to easily share more focused tools.

A.1

Developing for mobile and desktop
-
alternatives

Out of the b
ox
,

the default new project template will support mobile devices. The current
template renders identical styles in most browsers, requiring that users manually zoom and
2

Author

/
Title

Last saved:
12/10/2013

Chapter author name:

©Manning Publications Co.
Please post comments or corrections to the
Author Online forum:

http://www.manning
-
sandbox.com/forum.jspa?forumID=XYZ

pan to
use

the default navigation. The new template produce
s

markup that looks

okay, but
different, in both.


Figure A.1 The new project template rendered on a desktop browser

Last saved:
12/10/2013

Author

/
Title

3

Chapter author name:

©Manning Publications Co.
Please post comments or corrections to

the
Author Online forum:

http://www.manning
-
sandbox.com/forum.jspa?forumID=XYZ


4

Author

/
Title

Last saved:
12/10/2013

Chapter author name:

©Manning Publications Co.
Please post comments or corrections to the
Author Online forum:

http://www.manning
-
sandbox.com/forum.jspa?forumID=XYZ

Figure A.2 The new project template rendered on an iPhone

Microsoft is also including a new project template designed specifically for mobile and
tablet br
owsers. The new mobile template will leverage jQuery Mobile to produce something
more like the native experience on those devices.


Figure A.3 The
N
ew
P
roject dialog

box

offers a new
M
obile

Application

template

jQuery Mobile is a

t
ouch
-
o
ptimized


toolkit that unifies the user experience across
browsers on different types of devices.
It

support
s

iOS, Android, Blackberry
,

and, of course,
Windows Phone. This kit helps developers easily create familiar mobile interactions like page
Last saved:
12/10/2013

Author

/
Title

5

Chapter author name:

©Manning Publications Co.
Please post comments or corrections to

the
Author Online forum:

http://www.manning
-
sandbox.com/forum.jspa?forumID=XYZ

transitions, li
sts, sliders
,

and toggles. You can see more of jQuery Mobile at
http://jquerymobile.com/.

6

Author

/
Title

Last saved:
12/10/2013

Chapter author name:

©Manning Publications Co.
Please post comments or corrections to the
Author Online forum:

http://www.manning
-
sandbox.com/forum.jspa?forumID=XYZ


Last saved:
12/10/2013

Author

/
Title

7

Chapter author name:

©Manning Publications Co.
Please post comments or corrections to

the
Author Online forum:

http://www.manning
-
sandbox.com/forum.jspa?forumID=XYZ

Figure A.4 The mobile template rendered on an iPhone

ASP.NET MVC 4 is also slated to deliver a feature that allows developers to customize the
user experience on a
device
-
by
-
device basis. This feature

device
-
specific views

tackles a
growing problem in modern web development: where to decide what to render. Instead of
each view checking to see what browser it

s being rendered on, device
-
specific views render
the m
arkup for one experience, and the logic of deciding which experience to use is
centralized. The current plan is to leverage view file names to drive this convention. The
framework will still support
Index.cshtml

for regular desktop browsing and
Index.Mobil
e.cshtml

for mobile devices.

Also included is a facility called
DisplayModes

where the developer can build this
convention for maximum flexibility. In the
following
snippet
, the framework is instructed to
use
Index.iPhone.cshtml

when rendering on an
iPhone device:

DisplayModes.Modes.Insert(0, new DefaultDisplayMode("iPhone")

{


ContextCondition = (context => context.Request.UserAgent.IndexOf


("iPhone", StringComparison.OrdinalIgnoreCase) >= 0)

});

The developer can pass in a
Func<HttpContext, boo
l>

predicate that MVC will use to
choose the device
-
spe
cific view. In the
preceding
case
, if the
User
-
Agent

header contains
the term "iPhone", our iPhone views will be used.

The ASP.NET team has also put forth the idea of a device switcher

a widge
t that allows
users to switch from mobile to desktop view and back
. This is delivered as a Nu
G
et package
named
jQuery.Mobile.MVC
.
Installing this package will create a
ViewSwitcherController

that demonstrates how to manually override ASP.NET MVC 4
device
-
specific view conventions
.

A.2

Iterating on Razor

Razor is awesome, but one feature ASP.NET MVC 3 lacks is the ability to easily write Razor
helpers outside of regular views and share them across a project. This will be included in
ASP.NET MVC 4
,

along with t
he ability to compile these helpers into libraries for even easier
sh
aring across projects.

A.3

Leveraging NuGet and improved automation

Described as

extensible task
-
based tooling

,
r
ecipes

are little code
-
generation tools that
developers can share.

Some c
omponents are more than just views or code
t
hey require
developer inter
action to customize. With
r
ecipes, developers will have access to an API that
will allow them to generate the UIs that power this interaction.

Recipes can take the input
and execute
code generation to produce views, controllers
,

and other classes to be used

by
the consuming applic
ation.

8

Author

/
Title

Last saved:
12/10/2013

Chapter author name:

©Manning Publications Co.
Please post comments or corrections to the
Author Online forum:

http://www.manning
-
sandbox.com/forum.jspa?forumID=XYZ


Figure A.5 Consuming a
r
ecipe from Visual Studio

An example is an Ajax
g
rid.

A component like this might require several collaborating
pieces: vie
ws, controllers, scripts, stylesheets
,

and view models.

Imagine an interface where
you check some boxes, pick your columns, and choose a look and feel.
Click

the
Finish

button
and viola, a custom Ajax grid. In fact, recipes can include Windows Form
s
components: from humble dialog boxes to complex interfa
ces.

Last saved:
12/10/2013

Author

/
Title

9

Chapter author name:

©Manning Publications Co.
Please post comments or corrections to

the
Author Online forum:

http://www.manning
-
sandbox.com/forum.jspa?forumID=XYZ


Figure A.6 The new Run Recipe dialog box

There are two types of
r
ecipes:
f
ile
r
ecipes and
f
older
r
ecipes. Both interfaces,
IFileRecipe

and
IFolderRecipe
, implement a common
IRecipe

interf
ace
. This
IRecipe

will be exported by the R
ecipe assembly and consumed by
Visual Stud
io at design
time.
The following l
isting

shows a dummy implementation of this
t
est
r
ecipe, which does
pretty much nothing (at the time of
writing
,

r
ecipes
were in a very early stage).

Listing A.1
A dummy
FolderRecipe

implementation

[Export(typeof(IRecipe))]

public class TestRecipeRecipe : IFolderRecipe

{


public string Description


{


get { return "A test recipe"; }


}

10

Author

/
Title

Last saved:
12/10/2013

Chapter author name:

©Manning Publications Co.
Please post comments or corrections to the
Author Online forum:

http://www.manning
-
sandbox.com/forum.jspa?forumID=XYZ



public Icon Icon


{


get { return Resources.Icon; }


}



public string Name


{


get { return "Test Recipe"; }


}



public bool Execute(ProjectFolder folder)



{


return true;


}



public bool IsValidTarget(ProjectFolder folder)


{


return tru
e;


}

}

You might notice a
ProjectFolder

type. This is a new type in the Recipes API, and it
serves as a friendlier API to the Visual Studio environment API than developers are used to.
This is a good thing. The
f
ile
r
ecipes get access to a similar type
,
ProjectFile
.

The key here is that these
r
ecipes
will be optionally distributed via NuGet. While offering
solution
-
specific
r
ecipes
will be viable, the community of
r
ecipe
developers will build some
very cool stuff.

A.4

Scalability

Fina
lly, ASP.NET MVC 4 is slated to feature a few improvements towards greater scalability.
A built
-
in resource bundler will be available. Minimizing and packaging JavaScript and CSS
files has long been a burden for developers, and with version 4 the framework

will handle it.
Also, ASP.NET MVC 4 will lean on the new asynchronous syntax included with C# 5. In
version 3
,

writing asynchronous actions is possible but verbose and error
-
prone.
The new
await

keyword
will cut that code in half.

A.5

Anticipated dates and
more information

ASP.NET MVC 3 was released in January 2011. If the ASP.NET product team continues with
release cycles of about one year,
ASP.NET MVC 4 will be

released

in early 2012.

For more information about ASP.NET MVC 4, be sure to

visit the project

s home page on
Code
P
lex:
http://aspnet.codeplex.com/
.

The product team has released a roadmap of possible features in ASP.NET MVC 4 here:
http://aspnet.codeplex.com/wikipage?title=ASP.NET%20MVC%204%20RoadMap
.

Finally, the ASP.NET team has started maintaining an information site where authoritative
details will be released:
http://www.asp.net/mvc/mvc4
.


Last saved:
12/10/2013

Author

/
Title

11

Chapter author name:

©Manning Publications Co.
Please post comments or corrections to

the
Author Online forum:

http://www.manning
-
sandbox.com/forum.jspa?forumID=XYZ