static MasterService() { var slaves = new Dictionary <int, string>(); var config = new MyServiceLibrary.CustomSection.ConfigSettings(); foreach (var item in config.ServerElements) { slaves.Add(item.port, item.ip); } new SlaveService(); //this line is for scenario when slaves are not created. do we need this? var appDomainSetup = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, PrivateBinPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MasterDomain") }; AppDomain domain = AppDomain.CreateDomain("MasterDomain", null, appDomainSetup); var assembly = Assembly.Load("MyServiceLibrary"); master = (Master)domain.CreateInstanceAndUnwrap(assembly.FullName, typeof(Master).FullName, true, BindingFlags.Default, null, args: new object[] { slaves }, culture: null, activationAttributes: null); }
static SlaveService() { var dictionary = new Dictionary <int, string>(); slaves = new List <Slave>(); var config = new MyServiceLibrary.CustomSection.ConfigSettings(); foreach (var item in config.ServerElements) { var appDomainSetup = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, PrivateBinPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"SlaveDomain port {item.port} ip {item.ip}") }; AppDomain domain = AppDomain.CreateDomain($"SlaveDomain port {item.port} ip {item.ip}", null, appDomainSetup); var assembly = Assembly.Load("MyServiceLibrary"); slaves.Add((Slave)domain.CreateInstanceAndUnwrap(assembly.FullName, typeof(Slave).FullName, true, BindingFlags.Default, null, args: new object[] { item.port, item.ip }, culture: null, activationAttributes: null)); } }