YOUR FEEDBACK
Chris Keene's Prescription for Curing the Java Flu
Pedro wrote: "Adobe and Microsoft are doing a far better job making their ...

SYS-CON.TV
TOP MICROSOFT .NET LINKS


Mercado Eletrônico Case Study
Migrating from ASP/COM to .NET using Spring.NET

Digg This!

Page 2 of 2   « previous page

Application Configuration
In the past, many of our applications had their own way of retrieving their settings. The registry keys and configuration files were mainstream but there was no standardized higher-level approach to apply the lower-level configuration APIs consistently across the application. As a result, we essentially wrote all the code necessary for the whole application configuration in multiple ways in some ad hoc Init() method, resulting in duplicate code if a specific setting was reused across applications. This proved a development and deployment nightmare, since there was always a strong dependence on the configuration code.

Using Spring.NET, we can easily apply a comprehensive approach to application configuration instead of writing such functionality in-house. Objects that need some setting are simply "given" it through the dependency injection mechanism, using simple setter properties or even constructors. The source of these values can come from practically any source, such as the registry, configuration files, or custom providers. As an added benefit, with Spring.NET, we can configure each object separately - no need to configure the whole application at once - which is the direction that previous approaches to configuration led us towards.

Declarative, Distributed Transactions
Most of our business logic was written in Delphi, C++, or .NET serviced/enterprise components and made use of COM+ transactions; or worse, data access code managed their own transactions using the likes of BeginTrans() and RollbackTrans(). Some stored procedures did their own transaction-handling as well. Changing the transaction management strategy was difficult, since it was hard-coded. It also made debugging transactions and locking problems very hard, including all the MSDTC deployment problems.

Now we can abstract transaction management APIs away from the service layer code and into external configuration using Spring.NET's declarative transaction management features. Using simple C# attributes to hint about the transactional requirements of a specific service method, such as which exceptions should trigger a rollback, we can declaratively apply transactional functionality to the service layer. At a high level, Spring.NET lets us say, using a simple attribute: "Before this method, start a transaction; after this method, stop transaction; if it throws an exception, rollback."

Great technology from Microsoft, like TransactionScope transactions, which allow for automatic promoting from local (one single resource/database) to distributed (multiple different databases), is available to developers via Spring.NET. Spring.NET provides a transaction provider abstraction, letting you switch from using TransactionScope-based transaction management for distributed transactions to standard ADO.NET-based transaction management for local (non-distributed) transactions.

Business Logging via AOP
The nature of our business mandates that we have a very high level of logging. Most operations, from the simple create/insert/delete of a cost-center entity to the complex multi-item purchase order editing, had to be logged and traceable. This generally means that teams had to write specific logging code for each and every operation, leading to a complex mix of actually implementing the requirements and logging what was being done.
Using Aspect-Oriented Programming (AOP), we can now simply declare logging as an aspect and declaratively apply it to the relevant points in our system instead of writing similar logging statements in the code in hundreds of locations. In practice, Spring.NET lets us handle logging just like it handles transactions. We can define a logger object (in which we capture user context information, thread states, parameter values, etc.), inject its dependencies (e.g., the database where we persist the captured information), and apply it, via external configuration, to our business methods. Spring even lets us piggyback the logging advice on to the transactional advice, since most of the same methods that are transacted also need to be logged. For more information on Aspect-Oriented Programming see to the Wikipedia article http://en.wikipedia.org/wiki/Aspect-oriented_programming.

Exposing POCOs as Web Services or COM+ Components
Exposing the same functionality over different channels required us to duplicate a lot our code, or, at least, write different "wrapper" classes to adapt to each technology's requirements. Web Services require WebMethod annotations; COM+ components need to extend ServicedComponent, remoting calls for MarshalByRefObject, etc.

Spring.NET lets us expose our service implementations (which are actually POCOs, Plain Old C# Objects) as Web Services or enterprise services (COM+) using simple external configuration files. The great thing about this is that we can keep all the transactional and logging benefits while reusing a lot of code. In this way, a service method that was originally written for an ASP.NET page can be very simply reused when exposed as a Web Service, which is called by our Adobe Flex clients over HTTP. There's even no need to write wrapper .asmx files or classes.

Conclusion
When planning a new .NET application, or architecting a large migration to the .NET platform, it's important to keep in mind that even though a lot of frameworks are available, some are too cumbersome and demanding, or too much of an all or nothing deal. A good framework should "push" you in the right direction, make it easy to apply successful approaches, and marry best practices and reusable code artifacts in a way that actually improve application quality. We found this and more in the Spring.NET Framework, which is a spiritual port of the Spring Framework, famous and highly praised in Java circles. We could learn from the framework while it adapted to our needs and enjoy consistent development and excellent runtime performance in the .NET world. (See sidebar)


Page 2 of 2   « previous page

About Ricardo Pardini
Ricardo Pardini has been a technical lead at Mercado Eletrônico for five years and led the developer team on this .NET migration project. He specializes in virtualization, designing and developing rich Internet applications, and enjoys being a part of the prolific .NET and Java communities.

About Eric Lemes
Eric Lemes is a lead application designer and developer at Mercado Eletrônico. He focuses on the development of Web services and code infrastructure, and implemented many of the integration aspects discussed here.

MICROSOFT .NET LATEST STORIES
Peer Networking Series - A Closer Look at PNRP vs. Bonjour/ZeroConf
It seems as though whenever I bring up PNRP and its benefits, I am immediately inundated with a list of questions or comments indicating that Microsoft is re-inventing the wheel and that PNRP has already been implemented before in the form of ZeroConf and, more specifically, Apple's im
db4o Open Source Object-Oriented Database Supports LINQ
db4objects has announced that its db4o object database is now optimized for Microsoft's LINQ. With the new support, developers can choose an object-oriented optimized engine without changing the API or compromising performance. db4object's db4o database offers a persistence solution to
Microsoft, Unisys, Yahoo and Vista
Microsoft, which spent $6 billion on aQuantive and was chasing Yahoo for its ads before it came to a dead stop, has been supporting - as in helping write - legislation in New York and Connecticut that would regulate the data that companies like Yahoo and Google collect for targeted adv
AJAX World - Xceed Launches Microsoft Silverlight 2 Control
Xceed launched Xceed Upload for Silverlight, the commercial offering in support of Microsoft's promising new Silverlight technology. The product is available now for purchase or as a fully functional 45-day trial on Xceed's website. Xceed Upload for Silverlight lets developers add uplo
Microsoft To Keynote 4th International Virtualization Conference & Expo
Mike Neil is general manager for virtualization strategy in the Windows Server Division at Microsoft. Mike is focused on the delivery of the Windows virtualization technology, including Windows Server 2008 Hyper-V, Microsoft Hyper-V Server and Virtual PC 2007. Mike also directs the tec
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING NEWS FROM THE WIRES
High Growth Forecasted for the Mobile search 2008-2013: Profiting From Information and Advertising on the Move
Reportlinker.com announces that a new market research report related to the Wireless industr