I want to know if I can determine which appdomain created the object. This is for unit test, but also for useful general knowledge. I have the following code snippets (this is sample 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"); }
Then i call
Foo myFoo = Create();
What I would like to do is figure out which AppDomain method on myFoo will be called to verify that the Create method actually created the new AppDomain. I understand that I can add a method on foo like
public class Foo { public string appDomainName { get { return AppDomain.CurrentDomain.FriendlyName; } } }
This will provide me with the application Foo runs on. I do not think this is an elegant solution only for unit test. It would be great if someone could help determine a way like that.
public string GetAppDomainNameWithDotNetWitchcraft(Foo myFoo) {
EDIT: Thanks for the answers and comments. The question that I asked was answered, and the comments helped me understand where I was wrong. What I really tried to achieve was to verify that the new AppDomain was created.
btlog
source share