COMPARISON BETWEEN SPRING AND ASP.NET FRAMEWORKS Preeti Malik (pm2371) Instructor: Prof. Gail Kaiser COMS E6125: Web-enhanced Information Management (Spring 2009)
ASP.NET MVC IMPLEMENTATION Offers basic implementation of MVC design pattern Controllers are C# or VB.NET classes with public methods called actions. Every controller action returns an action result. 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.
SPRING 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 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
THE SPRING FRAMEWORK Courtesy [2] The Spring 2.0 Reference Manual
HOW ARE THE TWO MVCS DIFFERENT? SPRING Web module + other enterprise application modules All configuration stored in a separate XML configuration file (DI/IoC) Offers wide variety if Controllers depending on: - how much configuration we want to 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 ASP.NET Strictly a web MVC framework Configuration mainly maintained inside application source code Offers only one type of Controller Tight coupling between URL and Class action name Mature Handler Interceptors capable of pre- and post-request processing (using AOP) Offers different view technologies and provides wide variety of ViewResolvers Provides only pre-request processing Offers only one view format (.aspx pages)
DEPENDENCY INJECTION (DI) AND INVERSION OF CONTROL (IOC) 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 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 and objects are created using constructors.
DATA ACCESS 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 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.
DATA ACCESS CONTD. ASP.NET ADO.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. 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
CACHING Spring All 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. ASP.NET Output Caching: Stores web pages and user control responses Traditional Application Data Caching: Stores data objects, for example, records retrieved from database.
ASPECT-ORIENTED PROGRAMMING (AOP) AOP complements object-oriented programming by providing another way of thinking about program structure. Example: Logging, Filtering Spring 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 AspectDNG etc.
OTHER COMPARISONS Other Aspects Spring ASP.NET Validation Security Only server-side validations are included. Client-side validations are left to the developer. End configuration where application is deployed is not known. Acegi Security was born. Both client and serverside validations provided Benefits of the exhaustive Windows 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.
CONCLUSION ASP.NET Complete IDE Reduced Development Cycles Spring 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
REFERENCES [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 [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/dataaccess/> [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>
QUESTIONS?
THANK YOU