/// <summary> /// 获取出版商,如果没有,则创建一个(享元模式) /// </summary> /// <param name="request">服务请求对象</param> /// <returns>出版商</returns> public ServicePublisher GetPublisher(IServiceContext context) { ServiceRequest request = context.Request; bool sessionRequired = context.SessionRequired; string key = ""; if (request.RequestModel == RequestModel.ServiceEvent) { key = request.ServiceUrl; } else { key = string.Format("Publish://{0}/{1}", request.ServiceName, request.MethodName); } if (dict.ContainsKey(key)) { return(dict[key]); } else { lock (_syncLock) { if (dict.ContainsKey(key)) { return(dict[key]); } else { ServicePublisher pub = null; if (request.RequestModel == RequestModel.ServiceEvent) { pub = new EventServicePublisher(key, context); } else { if (sessionRequired) { pub = new SessionServicePublisher(key); } else { pub = new NoneSessionServicePublisher(key); } } dict[key] = pub; return(pub); } } } }
/// <summary> /// 获取出版商,如果没有,则创建一个(享元模式) /// </summary> /// <param name="request">服务请求对象</param> /// <returns>出版商</returns> public ServicePublisher GetPublisher(ServiceContext context) { ServiceRequest request = context.Request; bool sessionRequired = context.SessionRequired; ServicePublisher pub = null; string key = request.ServiceUrl; //if (request.RequestModel == RequestModel.ServiceEvent) // key = request.ServiceUrl; //else // key = string.Format("Publish://{0}/{1}", request.ServiceName, request.MethodName); if (dict.ContainsKey(key)) { pub = dict[key]; } else { lock (_syncLock) { if (dict.ContainsKey(key)) { pub = dict[key]; } else { if (request.RequestModel == RequestModel.ServiceEvent) { pub = new EventServicePublisher(key, context); } else { if (sessionRequired) { pub = new SessionServicePublisher(key); } else { pub = new NoneSessionServicePublisher(key); } pub.Context = context; } dict[key] = pub; } } } pub.AddProcessedRequest(request); return(pub); }