What is the "site" of the "component" in .net?

I am a new tester, and while reading legacy code, I had the following two classes:

public class TestCommon : Component { public void Initialize() { var serviceContainer = (IServiceContainer)this.GetService(typeof(TestFramework)); serviceContainer.AddService(typeof(TestCommon), this); } } public class TestFramework : ISite, IServiceContainer { readonly Hashtable services = new Hashtable(); public TestFramework() { this.AddService(this); var bedrockModuleInstance = (TestCommon)Activator.CreateInstance(typeof(TestCommon)); ((TestCommon)bedrockModuleInstance).Site = this; ((TestCommon)bedrockModuleInstance).Initialize(); } } 

I don’t understand why in the TestCommon Initialize class you can call GetService and somehow return TestFramework 'GetService? I tried to understand it by reading MSDN about the container, component, and site, but could not understand the idea of ​​the site.

Update: Read the GetService implementation, finding that the GetService component is actively returning its GetService site, answered my question.

  protected virtual object GetService(Type service) { ISite s = site; return((s== null) ? null : s.GetService(service)); } 
+6
source share
1 answer

Found the answer. Read the GetService implementation, finding that the GetService component is actively returning its GetService site, answered my question.

 protected virtual object GetService(Type service) { ISite s = site; return((s== null) ? null : s.GetService(service)); } 
+3
source

All Articles