Click here to Skip to main content
15,867,986 members
Articles / Web Development / ASP.NET

SPRING.NET + iBATIS.NET With ASP.NET MVC - Part 1

Rate me:
Please Sign up or sign in to vote.
4.75/5 (10 votes)
26 Apr 2009GPL36 min read 57.7K   39   10
This article explains how to make a web board with Spring.NET, Ibatis.NET Framework.

1. Introduction

Recently, Microsoft announced the ASP.NET MVC. A pattern that supports these features is the MVC (Model-View-Controller). The ASP.NET team has recognized the benefits of this pattern and is working to incorporate it into ASP.NET. This article will focus on building an ASP.NET MVC web application with SPRING.NET and iBATIS.NET.

1. 1. Prerequisites

  • OS: Windows Server 2003; Windows Server 2008; Windows Vista; Windows XP
  • IDE: Visual Studio 2008, Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1
  • Database: Microsoft SQL 2000 or higher
  • Framework: .NET 3.5 SP1
  • ASP.NET MVC 1.0 - Download
  • SPRING.NET 1.2.0 - Download
  • iBATIS.NET DataMapper 1.6.1 - Download

1. 2. What is SPRING.NET ?

SRING.NET is an application framework or lightweight container. It allows .NET developers who are building enterprise .NET application to get to the heart of their real domain problems and stop spending so much time on the minutiae of providing services to their domain. It also allows you to remove incidental complexity when using the base class libraries makes best practices, such as test driven development, easy practices.

The design of SPRING.NET is based on the Java version of the Spring Framework, which has shown real-world benefits and is used in thousands of enterprise apps world wide. but, SRING.NET is not a quick port from the Java version. I think .NET Framework is very powerful and made up of huge useful libraries. So, SRING.NET Framework is just helping .NET Framework.

1. 2. 1. Background

In early 2004, Martin Fowler asked the readers of his site: when talking about Inversion of Control: “the question is, what aspect of control are [they] inverting?”. Fowler then suggested renaming the principle (or at least giving it a more self-explanatory name), and started to use the term Dependency Injection. His article then continued to explain the ideas underpinning the Inversion of Control (IoC) and Dependency Injection (DI) principle. If you need a decent insight into IoC and DI, please do refer to the article: http://martinfowler.com/articles/injection.html.

1. 2. 2. Modules

Spring.Core is the most fundamental part of the framework allowing you to configure your application using Dependency Injection. Other supporting functionality, listed below, is located in Spring.Core.

Spring.Aop - Use this module to perform Aspect-Oriented Programming (AOP). AOP centralizes common functionality that can then be declaratively applied across your application in a targeted manner. Spring's aspect library provides predefined easy to use aspects for transactions, logging, performance monitoring, caching, method retry, and exception handling.

Spring.Data - Use this module to achieve greater efficiency and consistency in writing data access functionality in ADO.NET and to perform declarative transaction management.

Spring.Data.NHibernate - Use this module to integrate NHibernate with Spring’s declarative transaction management functionality allowing easy mixing of ADO.NET and NHibernate operations within the same transaction. NHibernate 1.0 users will benefit from ease of use APIs to perform data access operations.

Spring.Web - Use this module to raise the level of abstraction when writing ASP.NET web applications allowing you to effectively address common pain-points in ASP.NET such as data binding, validation, and ASP.NET page/control/module/provider configuration.

Spring.Web.Extensions - Use this module to raise the level of abstraction when writing ASP.NET web applications allowing you to effectively address common pain-points in ASP.NET such as data binding, validation, and ASP.NET page/control/module/provider configuration.

Spring.Services - Use this module to adapt plain .NET objects so they can be used with a specific distributed communication technology, such as .NET Remoting, Enterprise Services, and ASMX Web Services. These services can be configured via dependency injection and ‘decorated’ by applying AOP.

Spring.Testing.NUnit - Use this module to perform integration testing with NUnit.

SPRING.NET consist of 8 libraries. However, I'll use 3 libraries that are marked bold libraries (Core, Aop, Web).

The Spring.Core's DI is very useful function. That is completely disconnected the dependency.
And Spring.Aop provides declarative enterprise services, especially as a replacement for COM+ declarative services. The most important such service is declarative transaction management, which builds on Spring.NET's transaction abstraction. This functionality is planned for an upcoming release of Spring.NET.
Spring.Web is amazingly located in the top of the Spring IoC Container.

1. 2. 3. A Simple Example of SPRING.NET Configuration

XML
 <system.web>
    <httpHandlers>

        <add verb="*" path="*.aspx" 
		type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
    </httpHandlers>

    <httpModules>

        <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
    </httpModules>

    ...

</system.web>

1. 3. What is iBATIS.NET ?

The iBATIS is a simple but complete framework that makes it easy for you to map your objects to your SQL statements or stored procedures. One definition of a Mapper is an "object that sets up communication between two independent objects." A Data Mapper is a "layer of mappers that moves data between objects and a database while keeping independent of each other and the mapper itself." - Patterns of Enterprise Architecture(ISBN 0-321-12742-0) -

1. 3. 1. How Does iBATIS.NET Work?

  • Separating SQL code from programming code
  • Passing input parameters to the library classes and extracting the output
  • Caching often-used data until it changes
  • Managing transactions and threading
  • Using the Entity Class (in other words, VO;Value Object)

1. 3. 2. A simple Data Map

XML
 <?xml version="1.0" encoding="UTF-8" ?>
<sqlMap namespace="LineItem"     
        xmlns="http://ibatis.apache.org/mapping"     
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <!--Type aliases allow you to use a shorter name for long 
	fully qualified class names.-->
  <alias>
    <typeAlias alias="LineItem" 
	type="NPetshop.Domain.Billing.LineItem, NPetshop.Domain" />
  </alias>
  <statements>
    <insert id="InsertLineItem" parameterClass="LineItem">   
      INSERT INTO [LinesItem](Order_Id, LineItem_LineNum, 
		Item_Id, LineItem_Quantity, LineItem_UnitPrice)
      VALUES (#Order.Id#, #LineNumber#, #Item.Id#, #Quantity#, #Item.ListPrice#)  
	</insert>
  </statements>
</sqlMap>

This map takes some properties from a LineItem instance and merges the values into the SQL statement. The value-add is that our SQL is separated from our program code, and we can pass our LineItem instance directly to a library method:

VB.NET
Mapper.Instance().Insert("InsertLineItem", lineItem)

This code shows completely separating SQL code from programming code.

1. 4. ASP.NET MVC Life Cycle

요청① = Request① :)

ASP.NET MVC's Front Controller pattern has more complex life cycle than classic ASP.NET.
In addition, A front controller centralizes functions such as view selection, security, and templating, and applies them consistently across all pages or views. when the behavior of these functions need to change, only a small part of the application needs to be changed. It is often called Facade Pattern.

If you design for Facade pattern, that makes it easy implementing DI.

  1. Receive first request for the application. In the Global.asax file, Route objects are added to the RouteTable object.
  2. Perfume 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 RequestCntext(IHttpContext) object.
  3. Create MVC request handler: The MvcRouteHandler object creates an instance of the MvcHandler class and passes it the RequestContext instance.
  4. 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.
  5. 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.
  6. Execute result (result Views): 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.

About the Korea VB.NET User Group

Article History

  • Initial article - Saturday, April 25, 2009

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer Incruit
Korea (Republic of) Korea (Republic of)
Software developer in Korea.
Microsoft MVP - Visual Basic
Member of VB-Insiders Group.
Member of MHVB.net

Comments and Discussions

 
GeneralSource files Pin
dongdongpj27-Jul-09 17:42
dongdongpj27-Jul-09 17:42 
AnswerRe: Source files Pin
Moonhyuk27-Jul-09 19:19
Moonhyuk27-Jul-09 19:19 
GeneralRe: Source files Pin
dongdongpj29-Jul-09 16:01
dongdongpj29-Jul-09 16:01 
QuestionMicrosoft Provider Pattern? Pin
MurphTheGreat6-May-09 3:35
MurphTheGreat6-May-09 3:35 
AnswerRe: Microsoft Provider Pattern? [modified] Pin
Moonhyuk11-May-09 20:19
Moonhyuk11-May-09 20:19 
GeneralRe: Microsoft Provider Pattern? Pin
MurphTheGreat12-May-09 2:12
MurphTheGreat12-May-09 2:12 
GeneralWow Nice~~ Pin
opclo29-Apr-09 16:45
opclo29-Apr-09 16:45 
Generalinteresting Pin
Jeff Circeo27-Apr-09 21:36
Jeff Circeo27-Apr-09 21:36 
GeneralWow. Pin
woojja25-Apr-09 22:43
professionalwoojja25-Apr-09 22:43 
GeneralRe: Wow. Pin
Moonhyuk26-Apr-09 14:04
Moonhyuk26-Apr-09 14:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.