我使用第三方类和一些静态成员:

class TheirClass{ //from metadata
    static TheirType TheirProp
}

我在我的代码中使用该类的实例

class MyWorkLoad  {
    TheirClass theInstance
}

但我需要单独的上下文/域/无论如何

{//My Program
    var w1 = MyWorkFactory.Create();
        w1.doWorkBasedOnFreshContext()

    var w2 = MyWorkFactory.Create();    
        w2.doWorkBasedOnFreshContext(); //err, dirty context, shared with w1
 }

我尝试过创建子AppDomains但仍然获得相同的行为:

protected static AppDomain CreatedChildDomain(AppDomain parentDomain)
{
  Evidence evidence = new Evidence(parentDomain.Evidence);
  AppDomainSetup setup = parentDomain.SetupInformation;
  AppDomain.CreateDomain("Lab_"+generationCount, evidence, setup);
}

这是我用来实例化的工厂方法

public static MyWorkLoad Create(string LabConfigPath)
{
    AppDomain subdomain = CreatedChildDomain(AppDomain.CurrentDomain);

    ExeConfigurationFileMap fileMap =
        new ExeConfigurationFileMap();

    fileMap.ExeConfigFilename = LabConfigPath;
    var config =
        ConfigurationManager.OpenMappedExeConfiguration(fileMap,
            ConfigurationUserLevel.None);

    var conf = config.AppSettings.Settings;
    var nextWork = new MyWorkLoad(subdomain, conf);
    generationCount++;
    return nextWork;
}

我怎样才能达到理想的隔离行为?