Friday, February 19, 2010

ASP.NET MVC Overview

The Model-View-Controller (MVC) architectural pattern separates an application into three main components: the model, the view, and the controller. The ASP.NET MVC framework provides an alternative to the ASP.NET Web Forms pattern for creating Web applications. The ASP.NET MVC framework is a lightweight, highly testable presentation framework that (as with Web Forms-based applications) is integrated with existing ASP.NET features, such as master pages and membership-based authentication. The MVC framework is defined in the System.Web.Mvc assembly.

MVC design pattern

MVC is a standard design pattern that many developers are familiar with. Some types of Web applications will benefit from the MVC framework. Others will continue to use the traditional ASP.NET application pattern that is based on Web Forms and postbacks. Other types of Web applications will combine the two approaches; neither approach excludes the other.
The MVC framework includes the following components:
Models. Model objects are the parts of the application that implement the logic for the application's data domain. Often, model objects retrieve and store model state in a database. For example, a Product object might retrieve information from a database, operate on it, and then write updated information back to a Products table in a SQL Server database.
In small applications, the model is often a conceptual separation instead of a physical one. For example, if the application only reads a dataset and sends it to the view, the application does not have a physical model layer and associated classes. In that case, the dataset takes on the role of a model object.
Views. Views are the components that display the application's user interface (UI).

Typically, this UI is created from the model data. An example would be an edit view of a Products table that displays text boxes, drop-down lists, and check boxes based on the current state of a Product object.
Controllers. Controllers are the components that handle user interaction, work with the model, and ultimately select a view to render that displays UI. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction.

For example, the controller handles query-string values, and passes these values to the model, which in turn might use these values to query the database.
The MVC pattern helps you create applications that separate the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements. The pattern specifies where each kind of logic should be located in the application.

The UI logic belongs in the view. Input logic belongs in the controller. Business logic belongs in the model. This separation helps you manage complexity when you build an application, because it enables you to focus on one aspect of the implementation at a time. For example, you can focus on the view without depending on the business logic.
The loose coupling between the three main components of an MVC application also promotes parallel development. For example, one developer can work on the view, a second developer can work on the controller logic, and a third developer can focus on the business logic in the model.

What's New in the .NET Framework Version 4

What's New in the .NET Framework Version 4
The new features and improvements for .NET Framework 4 Beta 2 are described in the following sections:
· Application Compatibility and Deployment.
· Parallel Computing.
· Improved Security Model.
· Core New Features and Improvements
· Networking.
· Web.
· Client.
· Data.
· Communications and Workflow.

Application Compatibility and Deployment

The .NET Framework 4 Beta 2 is designed so that applications and components from earlier versions work smoothly, except in a limited number of known cases. If your application or component does not work after .NET Framework 4 Beta 2 is installed, please submit a bug on the Microsoft Connect Web site. You can test compatibility as described in the .NET Framework 4 Application Compatibility topic and learn about new features by using the Visual Studio 2010 and .NET Framework 4 Beta 1 Walkthroughs. For additional information and known migration issues, visit the .NET Framework Compatibility Blog.
The ComponentGuaranteesAttribute enables developers of class libraries to mark their libraries, types, and type methods with an attribute that indicates how clients can expect their existing code to run against future versions of the library.
The following sections describe deployment improvements.

Client Profile

The .NET Framework 4 Beta 2 Client Profile supports more platforms than in previous versions and provides a fast deployment experience for your Windows Presentation Foundation (WPF) or Windows Forms applications. For more information, see .NET Framework Client Profile.
In-Process Side-by-Side Runtime Host Activation
This feature enables an application to load and start multiple versions of the .NET Framework in the same process. For example, you can run applications that load add-ins that are based on the .NET Framework 2.0 SP1 and add-ins that are based on the .NET Framework 4 Beta 2 in the same process. Older components continue to use the older .NET Framework version, and new components use the new .NET Framework version.

Parallel Computing

The .NET Framework 4 Beta 2 introduces a new programming model for writing multithreaded and asynchronous code that greatly simplifies the work of application and library developers. The new model enables developers to write efficient, fine-grained, and scalable parallel code in a natural idiom without having to work directly with threads or the thread pool. The new Namespace and other related types support this new model. Parallel LINQ (PLINQ), which is a parallel implementation of LINQ to Objects, enables similar functionality through declarative syntax. For more information, see Parallel Programming in the .NET Framework.
The following sections describe synchronization and threading support for parallel computing.
Unified Model for Cancellation
The .NET Framework 4 Beta 2 provides a new unified model for cancellation of asynchronous operations. The new System.Threading ::
CancellationTokenSource class is used to create CancellationToken that may be passed to any number of operations on multiple threads. By cancelling the token source object, the IsCancellationRequested property on the token is set to true and the token’s wait handle is signaled, at which time any registered actions with the token are invoked. Any object that has a reference to that token can monitor the value of that property and respond as appropriate.

Thread-Safe Collection Classes

The new System.Collections.Concurrent namespace introduces several new thread-safe collection classes that provide lock-free access to items whenever useful, and fine-grained locking when locks are appropriate. The use of these classes in multi-threaded scenarios should improve performance over collection types such as ArrayList and List Of .
Synchronization Primitives
New synchronization primitives in the System.Threading namespace enable fine-grained concurrency and faster performance by avoiding expensive locking mechanisms.

Improved Security Model

The .NET Framework 4 Beta 2 provides a new simplified security mode. For more information, see Security Changes in the .NET Framework 4.


Core New Features and Improvements

The following sections describe new features and improvements provided by the common language runtime (CLR) and the base class libraries.
Diagnostics and Performance
Earlier versions of the .NET Framework provided no way to determine whether a particular application domain was affecting other application domains, because the operating system APIs and tools, such as the Windows Task Manager, were precise only to the process level. Starting with the .NET Framework 4 Beta 2, you can get processor usage and memory usage estimates per application domain.
The AppDomain class provides new resource monitoring properties. Application domain resource monitoring is available through the managed and native hosting APIs and event tracing for Windows (ETW). When this feature has been enabled, it collects statistics on all application domains in the process for the life of the process.
You can now access the ETW events for diagnostic purposes to improve performance. For more information, see CLR ETW Events and Using Event Tracing for Windows to Log CLR Events. Also see Performance Counters and In-Process Side-By-Side Applications.
In the .NET Framework 4 Beta 2, you can attach profilers to a running process at any point, perform the requested profiling tasks, and then detach the profiler. For more information, see the IClrProfiling::AttachProfiler method.
The HandleProcessCorruptedStateExceptionsAttribute attribute enables managed code to handle exceptions that indicate corrupted process state.
Garbage Collection
The .NET Framework 4 Beta 2 provides background garbage collection, which results in fewer pauses in your application's performance. For more information, see the entry So, what’s new in the CLR 4.0 GC? in the CLR Garbage Collector blog.

Code Contracts

Code contracts let you specify contractual information that is not represented by a method's or type's signature alone. The new System.Diagnostics.Contracts namespace contains classes that provide a language-neutral way to express coding assumptions in the form of preconditions, postconditions, and object invariants. The contracts improve testing with run-time checking, enable static contract verification, and support documentation generation. For more information, see Code Contracts.
Embedded Interop Types
You no longer have to ship primary interop assemblies (PIAs) to deploy applications that interoperate with unmanaged objects. In the .NET Framework 4 Beta 2, compilers can embed the parts of the interop assemblies that add-ins actually use, and type safety is ensured by the common language runtime.

Dynamic Language Runtime

The dynamic language runtime (DLR) is a new runtime environment that adds a set of services for dynamic languages to the CLR. The DLR makes it easier to develop dynamic languages to run on the .NET Framework and to add dynamic features to statically typed languages. To support the DLR, the new System.Dynamic namespace is added to the .NET Framework. In addition, several new classes that support the .NET Framework infrastructure are added to the System.Runtime.CompilerServices namespace. For more information, see Dynamic Language Runtime Overview.
Covariance and Contravariance
Several generic interfaces and delegates now support covariance and contravariance. For more information, see Covariance and Contravariance in Generics.

BigInteger and Complex Structures

The new System.Numerics
BigInteger structure is an arbitrary-precision integer data type that supports all the standard integer operations, including bit manipulation. It can be used from any .NET Framework language. In addition, some of the new .NET Framework languages (such as F# and IronPython) have built-in support for this structure.
The new System.Numerics Complex structure represents a complex number that supports arithmetic and trigonometric operations with complex numbers.
Tuples
The.NET Framework 4 Beta 2 adds new generic tuple classes, and also provides a Tuple class that contains static factory methods for creating tuples.
The .NET Framework 4 Beta 2 class library contains the new System.Runtime.ExceptionServices namespace, and adds the ability to handle corrupted state exceptions.
File System Enumerations
New file enumeration methods in the System.IO.Directory and System.IO.DirectoryInfo classes return IEnumerable

collections instead of arrays. For examples, see the Directory.EnumerateDirectories and DirectoryInfo .EnumerateDirectories methods.
The static System.IO .File class provides the new ReadLines methods that read lines from files into IEnumerable collections. These methods are useful in LINQ scenarios where you may want to quickly and efficiently query the contents of a text file and write the results to a log file without allocating any arrays.

Memory-Mapped Files

The .NET Framework now supports memory-mapped files. You can use memory-mapped files to edit very large files and to create shared memory for interprocess communication. The new System.IO .UnmanagedMemoryAccessor class enables random access to unmanaged memory, similar to the way the System.IO .UnmanagedMemoryStream class enables sequential access to unmanaged memory.
64-Bit Operating Systems and Processes
You can identify 64-bit operating systems and processes with the Environment Is64BitOperatingSystem and Environment .Is64BitProcess properties.
You can specify a 32-bit or 64-bit view of the registry with
the Microsoft.Win32 .RegistryView enumeration when you open base keys.
The new Microsoft.Win32 .RegistryOptions enumeration lets you specify a volatile registry key that does not persist after the computer restarts.

Other New Features

The following list describes additional new capabilities, improvements, and conveniences. Several of these are based on customer suggestions.
To support culture-sensitive formatting, the System.TimeSpan structure includes new overloads of the ToString, Parse, and TryParse methods, as well as new ParseExact and TryParseExact methods.
The new String .IsNullOrWhiteSpace method indicates whether a string is null, empty, or consists only of white-space characters. New overloads have been added to the String.Concat and String.Join methods that concatenate members of an IEnumerable.collections.
The new StringBuilder.Clear method removes all text.
The new Enum.HasFlag method determines whether one or more bit fields or flags are set in an enumeration value. The Enum.TryParse
method returns a Boolean value that indicates whether a string or integer value could be successfully parsed.
The System Version class includes new Version.Parse and Version.TryParse methods to convert the string representation of a version number to a Version object.
The System Environment SpecialFolder enumeration contains several new folders.
You can now easily copy one stream into another with the CopyTo method in classes that inherit from the Stream class.
The System.Resources.ResourceWriter class provides improved stream support.
New Path Combine method overloads enable you to combine file paths.
The new System IObservable
and System interfaces provide a generalized mechanism for push-based notifications.
The IntPtr and UIntPtr classes now include support for the addition and subtraction operators.
GZipStream classes have improved so that data that is already compressed is no longer inflated. Also, the 4-gigabyte size restriction for compressing streams has been removed.
The new Monitor.Enter(Object, Boolean ) method overload takes a Boolean reference and atomically sets it to true only if the monitor is successfully entered.
You can use the Thread .Yield method to have the calling thread yield execution to another thread that is ready to run on the current processor.
You can now parse System .Guid structures.

Web

The following sections describe new features in ASP.NET core services, Web Forms, Dynamic Data, and Visual Web Developer. For more information, see What's New in ASP.NET 4 and Visual Web Developer 2010.

ASP.NET Core Services and Web Forms

ASP.NET 4 introduces several features that improve core ASP.NET services such as output caching and session-state storage.
Web Forms has been a core feature in ASP.NET since the release of ASP.NET 1.0. Many enhancements have been made in this area for ASP.NET 4, including the following:
The ability to set meta tags by using the Page .MetaKeywords and Page MetaDescription page properties.
More control over view state by using the Control .ViewStateMode property for a page and for individual controls.
Easier ways to work with browser capabilities.
Support for using ASP.NET routing with Web Forms.
More control over generated IDs by using the Control.ClientIDMode property.
The ability to persist selected rows in data controls by using theGridView .EnablePersistedSelection and ListView.EnablePersistedSelection properties.
More control over the HTML that is rendered by the FormView and ListView controls.
Filtering support for data source controls by using the new QueryExtender control.
Charting support by using the new ASP.NET Chart control.

Dynamic Data

For ASP.NET 4, Dynamic Data has been enhanced to give you even more power for quickly building data-driven Web sites. This includes the following:
Automatic validation that is based on constraints that are defined in the data model.
The ability to easily change the markup that is generated for fields in the GridView and DetailsView controls by using field templates that are part of a Dynamic Data project.


Client

The following sections describe new features in Windows Presentation Foundation (WPF) and Managed Extensibility Framework (MEF).
Windows Presentation Foundation
In the .NET Framework 4 Beta 2, Windows Presentation Foundation (WPF) contains changes and improvements in many areas. This includes controls, graphics, and XAML. For more information, see What's New in WPF Version 4.
Managed Extensibility Framework
The Managed Extensibility Framework (MEF) is a new library in the .NET Framework 4 Beta 2 that helps you build extensible and composable applications. MEF enables you to specify points where an application can be extended, to expose services to offer to other extensible applications and to create parts for consumption by extensible applications. It also enables easy discoverability of available parts based on metadata, without the need to load the assemblies for the parts.
For more information, see Managed Extensibility Framework. For a list of the MEF types, see the System.ComponentModel.Composition namespace.


Data

ADO.NET provides new features for the Entity Framework, including Persistence-Ignorant Objects, functions in LINQ queries, and Customized Object Layer Code Generation. For more information, see What's New in ADO.NET.


Communications and Workflow

Windows Communication Foundation (WCF) provides messaging enhancements and seamless integration with Windows Workflow Foundation (WF). WF provides improvements in performance, scalability, workflow modeling, and an updated visual designer. For more information, see What's New in Windows Communicationand What's New in Windows Workflow Foundation.