Database SQL Oracle MySql
Saturday, March 22, 2014
What’s in the .NET Framework?

What’s in the .NET Framework?

Microsoft Intermediate Language (MSIL):
Specification for a platform independent, low-level, stack-based assembly-like language
Common Language Runtime (CLR):
A common runtime for all .NET applications, compiles and executes MSIL
Class libraries:
Common functionality that can be used by all languages
Includes Windows Forms for GUI development
Language compilers:
C#, C++, VB…
Distributed computing:
Networking using sockets, Remoting, Web Services and Applications using ASP.NET
Read More
Thursday, March 20, 2014
no image

The Data Access Layer

The data access layer is the simplest layer of the traditional three-tiered architecture.
Simply put, the data access layer calls stored procedures that reside in the database or executes dynamic
SQL against the database. In prior versions of the .NET Framework, as the developer you were responsible for making sure that you knew which type of ADO.NET object should execute a stored procedure
and what type of object should be passed back to the business layer. The debate about which object to
pass back to the business layer is always heated, but the .NET Framework has given us a tool that could
calm those debates.
Read More
ASP.NET MVC PAGE LIFE CYCLE

ASP.NET MVC PAGE LIFE CYCLE


What is ASP.NET MVC: ASP.NET MVC is a part of the ASP.NET Web application framework. It is one of the two different programming models you can use to create ASP.NET Web applications, the other being ASP.NET Web Forms.

An MVC Application is designed and implemented using the following three attributes




•      Model: The model contains the core information for an application. This includes the data and validation rules as well as data access and aggregation logic.
•    View: The view encapsulates the presentation of the application, and in ASP.NET this is
typically the HTML markup.
•      Controller: The controller contains the control‐flow logic. It interacts with the Model and Views to control the flow of information and execution of the application.

Page Life Cycle of ASP.NET MVC

Requests to an ASP.NET MVC‐based Web application first pass through the UrlRoutingModule object, which is an HTTP module. This module parses the request and performs route selection. The UrlRoutingModule object selects the first route object that matches the current request. (A route object is a class that implements RouteBase, and is typically an instance of the Route class.) If no routes match, the UrlRoutingModule object does nothing and lets the request fall back          to          the          regular          ASP.NET          or          IIS          request          processing. From  the  selected  Route  object,  the  UrlRoutingModule  object  obtains  the  IRouteHandler object that is associated with the Route object. Typically, in an MVC application, this will be an instance of MvcRouteHandler. The IRouteHandler instance creates an IHttpHandler object and


passes it the IHttpContext object. By default, the IHttpHandler instance for MVC is the MvcHandler object. The MvcHandler object then selects the controller that will ultimately handle the request.

The module and handler are the entry points to the ASP.NET MVC framework. They perform the following actions:

•    Select the appropriate controller in an MVC Web application.
•    Obtain a specific controller instance.
•    Call the controller's Execute method.

The following table lists the stages of execution for an MVC Web project.

Stage
Details
Receive      first
request for the application
In the Global.asax file, Route objects are added to the RouteTable object.
Perform
routing
The UrlRoutingModule module uses the first matching Route object in the
RouteTable collection to create the RouteData object, which it then uses to create a RequestContext (IHttpContext) object.
Create       MVC
request handler
The MvcRouteHandler object creates an instance of the MvcHandler class
and passes it the RequestContext instance.
Create controller
The MvcHandler object uses the RequestContext instance to identify the IControllerFactory object (typically an instance of the DefaultControllerFactory class) to create the controller instance with.
Execute
controller
The MvcHandler instance calls the controller's Execute method.
Invoke action
Most controllers inherit from the Controller base class. For controllers that do
so, the ControllerActionInvoker object that is associated with the controller determines which action method of the controller class to call, and then calls that method.
Execute result
A typical action method might receive user input, prepare the appropriate
response data, and then execute the result by returning a result type. The built‐in result types that can be executed include the following: ViewResult (which renders a view and is the most‐often used result type), RedirectToRouteResult, RedirectResult, ContentResult, JsonResult, and EmptyResult.




Figure 1: ASP.NET MVC Request



A URL Does Not Equal a Page


When  you  build  a traditional ASP.NET Web  Forms application or  an  Active  Server Pages  application, there is a one‐to‐one correspondence between a URL and a page. If you request a page named SomePage.aspx from the server, then there had better be a page on disk named SomePage.aspx. If the SomePage.aspx file does not exist, you get an ugly 404 – Page Not Found error. When building an ASP.NET MVC application, in contrast, there is no correspondence between the URL that you type into your browser’s address bar and the files that you find in your application. In an ASP.NET MVC application, a URL corresponds to a controller action instead of a page on disk. In a traditional ASP.NET or ASP application, browser requests are mapped to pages. In an ASP.NET MVC application, in contrast, browser requests are mapped to controller actions. An ASP.NET Web Forms application is content‐centric. An ASP.NET MVC application, in contrast, is application logic centric.
Read More
Design Patterns

Design Patterns

Design patterns are recurring solutions to software design problems you find again and again in real-world application development. Patterns are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges.

The Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral. Here you will find information on these important patterns.
To give you a head start, the C# source code is provided in 2 forms: 'structural' and 'real-world'. Structural code uses type names as defined in the pattern definition and UML diagrams. Real-world code provides real-world programming situations where you may use these patterns.
A third form, '.NET optimized' demonstrates design patterns that exploit built-in .NET 3.5 features, such as, generics, attributes, delegates, object and collection initializers, automatic properties, and reflection. These and much more are available in our Design Pattern Framework 3.5TM. See our Singleton page for a .NET 3.5 Optimized code sample.

  Creational Patterns
  Creates an instance of several families of classes
  Builder
  Separates object construction from its representation
  Creates an instance of several derived classes
  A fully initialized instance to be copied or cloned
  A class of which only a single instance can exist

  Structural Patterns
  Adapter
  Match interfaces of different classes
  Bridge
  Separates an object’s interface from its implementation
  A tree structure of simple and composite objects
  Add responsibilities to objects dynamically
  Facade
  A single class that represents an entire subsystem
  A fine-grained instance used for efficient sharing
  Proxy
  An object representing another object

  Behavioral Patterns
  A way of passing a request between a chain of objects
  Command
  Encapsulate a command request as an object
  A way to include language elements in a program
  Sequentially access the elements of a collection
  Defines simplified communication between classes
  Memento
  Capture and restore an object's internal state
  A way of notifying change to a number of classes
  State
  Alter an object's behavior when its state changes
  Encapsulates an algorithm inside a class
  Defer the exact steps of an algorithm to a subclass
  Visitor
  Defines a new operation to a class without change

 

 



Definition of singleton pattern

Ensure a class has only one instance and provide a global point of access to it.
singleton pattern is a design pattern used to implement the mathematical concept of a singleton, by restricting the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects .
Common uses
  • The Abstract Factory, Builder, and Prototype patterns can use Singletons in their implementation.
  • Facade objects are often Singletons because only one Facade object is required.
  • State objects are often Singletons.
  • Singletons are often preferred to global variables because:
    • They don't pollute the global namespace (or, in languages with namespaces, their containing namespace) with unnecessary variables
    • They permit lazy allocation and initialization, whereas global variables in many languages will always consume resources.
Class diagram

Implementation

Implementation of a singleton pattern must satisfy the single instance and global access principles. It requires a mechanism to access the singleton class member without creating a class object and a mechanism to persist the value of class members among class objects. The singleton pattern is implemented by creating a class with a method that creates a new instance of the class if one does not exist. If an instance already exists, it simply returns a reference to that object. To make sure that the object cannot be instantiated any other way, the constructor is made protected (not private, because reuse and unit test could need to access the constructor). Note the distinction between a simple static instance of a class and a singleton: although a singleton can be implemented as a static instance, it can also be lazily constructed, requiring no memory or resources until needed. Another notable difference is that static member classes cannot implement an interface, unless that interface is simply a marker. So if the class has to realize a contract expressed by an interface, it really has to be a singleton.

The singleton pattern must be carefully constructed in multi-threaded applications. If two threads are to execute the creation method at the same time when a singleton does not yet exist, they both must check for an instance of the singleton and then only one should create the new one. If the programming language has concurrent processing capabilities the method should be constructed to execute as a mutually exclusive operation.

·         The classic solution to this problem is to use mutual exclusion on the class that indicates that the object is being instantiated.

Traditional simple way

This solution is thread-safe without requiring special language constructs, but it may lack the laziness of the one below. The INSTANCE is created as soon as the Singleton class is initialized. That might even be long before getInstance() is called. It might be (for example) when some static method of the class is used. If laziness is not needed or the instance needs to be created early in the application's execution, or your class has no other static members or methods that could prompt early initialization (and thus creation of the instance), this (slightly) simpler solution can be used:

C#

/// <summary>
/// Thread-safe singleton example created at first call
/// </summary>
public sealed class Singleton
{
    private static readonly Singleton _instance = new Singleton();
 
    private Singleton() { }
 
    public static Singleton Instance
    {
        get
        {
           return _instance;
        }
    }
}


Abstract Factory definition

Provide an interface for creating families of related or dependent objects without specifying their concrete classes.


Read More
Copyright © 2014 ASP.NET & C# & IIS & Crystal Report & Database & ADO.NET All Right Reserved
Designed by ASP.NET Tuts