I think you're on the right track. Here is what I've done in the past:
public class CassandraDAO
{
private Cluster cluster;
private Session session;
private String NODE = ABCServiceTester.Properties.Settings.Default.CASSANDRA_NODE;
private String USER = ABCServiceTester.Properties.Settings.Default.USERNAME;
private String PASS = ABCServiceTester.Properties.Settings.Default.PASSWORD;
public CassandraDAO()
{
connect();
}
private void connect()
{
cluster = Cluster.Builder().WithCredentials(USER, PASS)
.AddContactPoint(NODE).Build();
session = cluster.Connect();
}
protected Session getSession()
{
if (session == null)
{
connect();
}
return session;
}
}
With my connection details isolated in my CassandraDAO class, I then write individual DAOs for each keyspace or area of functionality. These DAOs then inherit the CassandraDAO class.
public class ProductsDAO : CassandraDAO
{
public List<Product> getProducts(string _itemID)
{
string strCQL = "SELECT priceAvail, productGroup, productSpec, sizeProfile "
+ "FROM products.itemsmaster "
+ "WHERE itemID=?";
Session localSession = getSession();
PreparedStatement statement = localSession.Prepare(strCQL);
BoundStatement boundStatement = new BoundStatement(statement);
boundStatement.Bind(_itemID);
//get result set from Cassandra
RowSet results = localSession.Execute(boundStatement);
List<Product> returnVal = new List<Product>();
foreach (Row row in results.GetRows())
{
Product tempProd = new Product();
tempProd.itemID= _itemID;
tempProd.priceAvail = row.GetValue<int>("priceavail");
tempProd.productGroup = row.GetValue<string>("productgroup");
tempProd.productSpec = row.GetValue<string>("productspec");
tempProd.sizeProfile = row.GetValue<string>("sizeprofile");
returnVal.Add(tempProd);
}
return returnVal;
}
There isn't a whole lot of official DataStax code out there for C#. I adapted this from what I learned by taking the Cassandra Java Development class on DataStax Academy. Obviously, I wasn't doing MVC in this example, but I hope it helps.