C
OMPARISON BETWEENSPRING
ANDASP.NET
FRAMEWORKSPreeti Malik (pm2371)
Instructor: Prof. Gail Kaiser
COMS E6125: Web-enhanced Information Management (Spring 2009)
ASP.NET MVC
IMPLEMENTATION
Offers basic implementation of MVC design patternControllers are C# or VB.NET classes with public
methods called ‘actions’. Every controller action returns an action result.
URL: localhost:8080/DayPlanner/MyController/handleRequest URL: localhost:8080/DayPlanner/MyController/handleRequest
Views are .aspx pages + master pages + code behind
classes. These are one type of action result.
Model classes use ADO.NET API to fetch data from
database. There is a parameter in the .aspx page called ‘inherits’ using which you can associate a model class with a view.
S
PRING
MVC
IMPLEMENTATION
More comprehensive implementation of the MVC design
pattern.
Made up of simple plain-old-Java-objects or beans defined in
a single XML configuration file.
Uses ‘Handler Mappings’ to map incoming requests to a Uses ‘Handler Mappings’ to map incoming requests to a
corresponding Controller.
Every Controller returns an instance of ModelAndView class. The view name is resolved to a particular view (JSP, Velocity
Template) using ViewResolvers.
Model consists of a reference data hash map:
Command object Other reference data
T
HE
S
PRING
F
RAMEWORK
H
OW ARE THE TWOMVC
S DIFFERENT?
SPRING ASP.NET
Web module + other enterprise application modules
Strictly a web MVC framework
All configuration stored in a separate XML configuration file (DI/IoC)
Configuration mainly maintained inside application source code
Offers wide variety if Controllers depending on:
- how much configuration we want to specify and where
Offers only one type of Controller
specify and where
- amount of coupling between Controller and View through the command object
Several types of Handler Mappings provide flexibility in mapping URLs to Controllers
Tight coupling between URL and Class action name
Mature Handler Interceptors capable of pre- and post-request processing (using AOP)
Provides only pre-request processing
Offers different view technologies and provides wide variety of ViewResolvers
D
EPENDENCY
I
NJECTION
(DI)
AND
I
NVERSION OF
C
ONTROL
(I
O
C)
Spring
Implemented through the Java classes of the IoC
Container
Configuration file is parsed to create fully populated
java object for each of the beans java object for each of the beans
Birth of SPRING.NET
ASP.NET
Need to use pluggable frameworks like Castle,
ObjectBuilder, StructureMap or Microsoft Entity Framework (MEF) to achieve DI/IoC
The model class may have one bean inside another
D
ATA
A
CCESS
Managing complex SQL queries and transactions in
industry projects needs use of frameworks like Hibernate, iBATIS etc.
Spring
Provides a consistent API to deal with each Provides a consistent API to deal with each
framework in a vendor database-independent way.
ORM and DAO modules contain the classes that
compose this generic API.
Provides common way to deal with exceptions
specific to a database
Provides its own transaction management and is also
capable of using transaction management from these frameworks.
D
ATA
A
CCESS
C
ONTD
.
ASP.NETADO.NET is used to connect to Microsoft supported
databases like MS SQL Server, MS Access etc.
Unlike Spring, the programming interface for a MS
SQL Server is different from a MS Access. SQL Server is different from a MS Access.
ADO.NET is capable of parsing XML data and
writing into a XML file. This feature is absent in Spring
Transaction management is provided by ADO.NET,
COM+ and classes in the System.Transactions namespace
C
ACHING
SpringAll beans are singletons. The instance of each bean is
cached for all requests.
Caching content like web pages is left to the
developer or to third party frameworks like Jcache or Ehcache.
Ehcache.
ASP.NET
Output Caching: Stores web pages and user control
responses
Traditional Application Data Caching: Stores data
A
SPECT
-O
RIENTED
P
ROGRAMMING
(AOP)
AOP complements object-oriented programming
by providing another way of thinking about program structure.
Example: Logging, Filtering SpringSpring
Custom aspects can be written
AOP module provides methods such as preHandle()
and postHandle() for this purpose
Handler Interceptors are used for filtering ASP.NET
Does not directly support AOP
Makes use of external frameworks like Aspect# and
O
THER COMPARISONS
Other Aspects Spring ASP.NET
Validation Only server-side
validations are included. Client-side validations are left to the developer.
Both client and server-side validations provided
Security End configuration where application is deployed is not known. Acegi
Benefits of the
exhaustive Windows authentication,
is not known. Acegi Security was born.
authentication, impersonation and authorization done by the OS and the IIS web server.
Testing - Unit testing possible because beans are loosely coupled
- Libraries included for integration testing
Doesn’t by itself provide classes for testing.
Depends on Visual Studio IDE and other provided namespaces for this purpose.
C
ONCLUSION
ASP.NETComplete IDE
Reduced Development Cycles
Spring
Demands a steeper learning curve of the developer Demands a steeper learning curve of the developer
Comprehensive infrastructural support for developing
enterprise applications
Recognizes several vendor solutions and provides a
consistent interface to each
It employs best practices in a highly tuned manner
and uses proven patterns to help construct robust applications
R
EFERENCES
[1] Microsoft MSDN Library Whitepapers, ASP.NET and Struts: Web Application Architectures <http://msdn.microsoft.com/en-us/library/aa478961.aspx>
[2] Spring Source, The Spring 2.0 Reference Manual <http://www.springsource.org/documentation>
[3] The official Microsoft ASP.NET MVC tutorials http://www.asp.net/Learn/mvc/ [4]Thomas Risberg, Rick Evans, Portia Tung, Developing a Spring framework MVC
application http://static.springframework.org/docs/Spring-MVC-step-by-step/ [5] Microsoft Whitepapers. Why ASP.NET?
http://www.asp.net/whitepaper/whyaspnet.aspx?tabindex=0&tabid=1 http://www.asp.net/whitepaper/whyaspnet.aspx?tabindex=0&tabid=1
[6] Billy McCafferty, Dependency Injection for Loose Coupling in .NET. April 2006.
http://www.codeproject.com/KB/architecture/DependencyInjection.aspx [7] The official ASP.NET Data Access Tutorials
<www.asp.net/Learn/data-access/>
[8] Microsoft MSDN library. ASP.NET Caching features <msdn.microsoft.com/en-us/library/xsbfdd8c(VS.71).aspx>
[9] F. Schmied and A. Cyment. Whitepaper on Aspect-oriented weaving and the .NET common language runtime. IET Softw., Vol. 1, No. 6, December 2007
<http://ieeexplore.ieee.org/ielx5/4124007/4435100/04435104.pdf?arnumber =4435104>