[CSHARP-686] Replace RequestStart/Done with thread agnostic concepts of "binding" and "bound objects" Created: 17/Feb/13  Updated: 20/May/19  Resolved: 20/May/19

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.7
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-203 Plugin load balancer for distributing... Closed
Epic Link: New Client API

 Description   

In 1.7 database and collection objects can be considered to be "bound" to a cluster, since operations can be performed against any member of the cluster (subject to any ReadPreference provided).

The only mechanism provided to "bind" a series of operations to a single connection is RequestStart/Done. But RequestStart/Done is problematic because it relies on thread affinity, which makes it very unfriendly to a future async implementation.

We are going to obsolete RequestStart/Done and replace it with a new concept we call "binding". In general terms, an IMongoBinding can be thought of as a source of bound objects, and a bound object is one that performs operations using a connection provided by the binding it is bound to.

The following classes are "bindings": MongoClient/MongoServer, MongoServerInstance and MongoConnection. They represent successively tighter bindings.

The following classes are "bound objects": MongoDatabase and MongoCollection.

Here is some sample code showing how to perform a series of operations using a single connection:

using (var connection = server.GetConnection())
{
    var database = connection.GetDatabase("test"); // database is bound to the connection
    var collection = database.GetCollection("test"); // and collection is also
    // perform a series of operations
}

Note that the connection is used in a "using" statement, and will be released back to the connection pool when the using statement is left.

This will be backward breaking if you use RequestStart/Done. In version 1.8 we are only deprecating RequestStart/Done, but in a later version it will be removed.



 Comments   
Comment by Ian Whalen (Inactive) [ 20/May/19 ]

Closing as Gone Away given the implementation of client sessions.

Generated at Wed Feb 07 21:37:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.