public void StreamStartHandle(XmppStream xmppStream, Stream stream, XmppHandlerContext context) { lock (this) { //Check tennats here if (ValidateHost(stream.To)) { //Create new services foreach (var template in templates) { var service = (IXmppService)Activator.CreateInstance(template.Value); service.Jid = new Jid(Stringprep.NamePrep(string.Format("{0}.{1}", template.Key, stream.To.Server).Trim('.'))); if (serviceManager.GetService(service.Jid) != null) { continue; } service.Name = service.Jid.ToString(); if (!string.IsNullOrEmpty(template.Key)) { service.ParentService = serviceManager.GetService(new Jid(Stringprep.NamePrep(stream.To.Server))); } service.Configure(new Dictionary <string, string>()); serviceManager.RegisterService(service); } //Reroute handlerManager.ProcessStreamStart(stream, Uri.CLIENT, xmppStream); } else { context.Sender.SendToAndClose(xmppStream, XmppStreamError.HostUnknown); } } }