G
Guest
I am in a slight predicament trying to determine the most efficient and
effective way to connect/disconnect from a database within a business object
(c# dll). I'm also keeping in mind the concept of connecting late and
disconnecting early.
Background:
- multi-tier application (code-behind uses properties and methods of the
business object, the business object handles the data layer)
For instance (in an ASPX code-behind file):
MyClass MyObject = new MyClass();
MyObject.Property1 = x;
MyObject.DoSomething();
When should the MyClass class connect and disconnect from the database?
Right now I am looking at 3 avenues of approach:
1. Connect in the constructor, then disconnect in Dispose()
2. Connect and Disconnect from within DoSomething()
3. Implement additional methods called Connect() and Disconnect()
I like number 2 except that, what happens when I get into a looping
situation where I repetitively call DoSomething(). Number 1 is good, except
I have to explicitly call Dispose() and of course implement IDisposable. I
really hate number 3 because it seem like unnecessary steps performed by the
consumer of the business object.
I'm looking for answers in the realms of what the best answer is from a
solution design perspective... keeping in mind: performance, scalability,
maintainability, and all that other fun stuff.
effective way to connect/disconnect from a database within a business object
(c# dll). I'm also keeping in mind the concept of connecting late and
disconnecting early.
Background:
- multi-tier application (code-behind uses properties and methods of the
business object, the business object handles the data layer)
For instance (in an ASPX code-behind file):
MyClass MyObject = new MyClass();
MyObject.Property1 = x;
MyObject.DoSomething();
When should the MyClass class connect and disconnect from the database?
Right now I am looking at 3 avenues of approach:
1. Connect in the constructor, then disconnect in Dispose()
2. Connect and Disconnect from within DoSomething()
3. Implement additional methods called Connect() and Disconnect()
I like number 2 except that, what happens when I get into a looping
situation where I repetitively call DoSomething(). Number 1 is good, except
I have to explicitly call Dispose() and of course implement IDisposable. I
really hate number 3 because it seem like unnecessary steps performed by the
consumer of the business object.
I'm looking for answers in the realms of what the best answer is from a
solution design perspective... keeping in mind: performance, scalability,
maintainability, and all that other fun stuff.