Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Control Transaction Boundaries Between Layers : Page 4

A connection broker enables your business layer to control transaction boundaries in a compact and efficient way. Learn how to roll your own broker to centralize and manage your application code's access to database resources.


advertisement
Small Glitch in the Classes
Finally, a small problem slightly breaks the polymorphism of the SmartConnection and SmartTransaction classes. In the data-layer code, you need to assign the connection object and eventually the transaction object to a command object at some point. While the signature of the command's connection property accepts any object implementing IDbConnection, you cannot pass a SmartConnection instance. Each provider-specific command instance casts the provided connection internally, throwing an exception if it doesn't receive a connection object of the same provider. Obviously, the same problem applies to the command's transaction property.

Instead of exposing the internal connection and transaction objects, you can resolve the issue by implementing the following methods in the SmartConnection and SmartTransaction methods, respectively:

public void SetConnectionToCommand( IDbCommand p_command ) { p_command.Connection = ms_RealConnection ; } public void SetTransactionToCommand(IDbCommand p_command ) { p_command.Transaction = ms_RealTransaction; }



Business Transactions with Less Overhead
The connection broker approach to transaction management fits the bill in most three-layered architectures. It incurs much less overhead than transactions based on COM+, so consider it in your application design when transaction boundaries are included into a single process and do not involve access to more than one resource manager.

Don't be afraid to adopt this approach simply because you may need COM+ transactions in a future. Provided you follow a stateless approach in your business-layer design, you can easily switch to transactions based on COM+ later, by simply inheriting your business objects from the ServicedComponent class and instructing the connection broker to ignore all calls related to transaction control.



Enrico Sabbadin is a software architect and developer who specializes in the Microsoft platforms. He trains and consults for Francesco Balena's Code Architects in .NET, application design, and security. He also maintains his own site for MTS, COM+, VBCOM, and .NET Enterprise Services FAQs.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date