I'm just starting a new project and using CSLA async await syntax for the first time, I'm experiencing an issue with the ConnectionManager<C> when running a MS Test, in that sometimes ConnectionManager<C>.GetManager() contains a disposed Connection.
I have identified that DeRef() disposes the Connection but does not always remove the ConnectionManager from LocalContext (LocalContext.Contains(contextName) == false on the thread that is calling it, so can not find it to remove it).
When GetManager() is called for a second time (LocalContext.Contains(contextName) == true, as it was not removed in DeRef(), and) returns the original ConnectionManager which has the disposed Connection.
I can solve the issue by replacing the use of ApplicationContext.LocalContext with a static Dictionary<string, ConnectionManager<C>>, but I suspect there is a good reason why LocalContext is being used?
Some abbreviated code for context...
[TestMethod]
public async Task MyTest()
{
var cust1 = await Customer.GetAsync(1);
var cust2 = await Customer.GetAsync(2);
...
private async Task DataPortal_Fetch(int id)
{
using (var manager = ConnectionManager<SqlConnection>.GetManager(connStr, false))
{
...
}
I'm using .ConfigureAwait(false) in all but the top level DataPortal_XYZ methods.
Any suggestions?
Regards
Peran
Copyright (c) Marimer LLC