I want to know if I can tell what appdomain a object was created in. This is for a unit test but also useful general knowledge. I have the following pieces of code (this is example code for illustration).
public Foo Create()
{
AppDomainSetup appDomainSetup =
new AppDomainSet { ApplicationBase = @"z:\SomePath" }
AppDomain appDomain =
AppDomain.CreateDomain("DomainName", null, appDomainSetup);
return (Foo) appDomain.CreateInstanceAndUnwrap("MyAssembly", "MyClass");
}
I then call
Foo myFoo = Create();
What I would like to be able to do is find out what AppDomain method on myFoo will be called in, to test that the Create method had actually created a new AppDomain. I realise that I can add a method on Foo like
public class Foo
{
public string appDomainName
{
get { return AppDomain.CurrentDomain.FriendlyName; }
}
}
This would provide me the appdomain that Foo is running in. I don't think this is an elegant solution just for a unit test. It would be great if someone could help define a method like.
public string GetAppDomainNameWithDotNetWitchcraft(Foo myFoo)
{
// Insert voodoo here.
}
EDIT: Thanks for the responses and comments. The question I have asked has been answered and the comments have helped me realised where I was going wrong. What I really was trying to achieve is to test that a new AppDomain is created.