System.ServiceModel.ServiceBehaviorAttribute.GetWellKnownSingleton C# (CSharp) Метод

GetWellKnownSingleton() публичный Метод

public GetWellKnownSingleton ( ) : object
Результат object
		public object GetWellKnownSingleton ()
		{
			return singleton;
		}

Usage Example

        protected override System.ServiceModel.Description.ServiceDescription CreateDescription(out IDictionary <string, ContractDescription> implementedContracts)
        {
            System.ServiceModel.Description.ServiceDescription service;
            if (this.serviceType == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxServiceHostCannotCreateDescriptionWithoutServiceType")));
            }
            if (this.SingletonInstance != null)
            {
                service = System.ServiceModel.Description.ServiceDescription.GetService(this.SingletonInstance);
            }
            else
            {
                service = System.ServiceModel.Description.ServiceDescription.GetService(this.serviceType);
            }
            ServiceBehaviorAttribute attribute = service.Behaviors.Find <ServiceBehaviorAttribute>();
            object wellKnownSingleton          = attribute.GetWellKnownSingleton();

            if (wellKnownSingleton == null)
            {
                wellKnownSingleton      = attribute.GetHiddenSingleton();
                this.disposableInstance = wellKnownSingleton as IDisposable;
            }
            if ((typeof(IServiceBehavior).IsAssignableFrom(this.serviceType) || typeof(IContractBehavior).IsAssignableFrom(this.serviceType)) && (wellKnownSingleton == null))
            {
                wellKnownSingleton      = System.ServiceModel.Description.ServiceDescription.CreateImplementation(this.serviceType);
                this.disposableInstance = wellKnownSingleton as IDisposable;
            }
            if ((this.SingletonInstance == null) && (wellKnownSingleton is IServiceBehavior))
            {
                service.Behaviors.Add((IServiceBehavior)wellKnownSingleton);
            }
            ReflectedContractCollection contracts  = new ReflectedContractCollection();
            List <System.Type>          interfaces = ServiceReflector.GetInterfaces(this.serviceType);

            for (int i = 0; i < interfaces.Count; i++)
            {
                System.Type key = interfaces[i];
                if (!contracts.Contains(key))
                {
                    ContractDescription item = null;
                    if (wellKnownSingleton != null)
                    {
                        item = ContractDescription.GetContract(key, wellKnownSingleton);
                    }
                    else
                    {
                        item = ContractDescription.GetContract(key, this.serviceType);
                    }
                    contracts.Add(item);
                    Collection <ContractDescription> inheritedContracts = item.GetInheritedContracts();
                    for (int j = 0; j < inheritedContracts.Count; j++)
                    {
                        ContractDescription description3 = inheritedContracts[j];
                        if (!contracts.Contains(description3.ContractType))
                        {
                            contracts.Add(description3);
                        }
                    }
                }
            }
            this.reflectedContracts = contracts;
            implementedContracts    = contracts.ToImplementedContracts();
            return(service);
        }