views:

29

answers:

1

The question is whether it's better to encapsulate general data code within a server control or bind the data to the control from the client?

The control will be utilized by various different applications and the data is generally only for the control. So the question is, rather than duplicate the code to bind the control in every client, would it be better to let the control access the data itself?

EDIT: If the control gets data directly what would be the best way to pass an NHibernate connection?

A: 

It depends on the situation. A general rule of thumb that I follow is to use the approach that uses the least repeated code.

In your situation, it sounds like it should be in the control.

The purpose for this philosophy is easier maintenance:

If the data source changes, or the query changes, I want to change it in code as few places as possible, so if you can change it ONCE by changing the control, it's a lot easier than changing things in all of the pages that use the control.

Edit - added

Better yet would be to have the control calling a stored procedure because it's generally easier to modify a stored procedure than it is to re-deploy code that's been modified into a live environment. Of course, the code for calling the stored procedure could be in the control in your situation. Again, refer to the purpose of the philosophy.

David Stratton
This was my thinking as well. I'm not sure yet whether I'll use procedures yet as I may utilize nHibernate since the logic and data code for the control would be encapsulated and used only within the control. The ORM would help cut down on lines to get and retrieve, mapping, caching, etc.
suedeuno