示例#1
0
        /// <summary>
        /// Creates the specified HttpHostContext
        /// </summary>
        public RestService(Type behaviorType)
        {
            this.m_serviceType = behaviorType;
            var behaviorAttribute = behaviorType.GetCustomAttribute <ServiceBehaviorAttribute>();

            this.m_serviceMode = behaviorAttribute?.InstanceMode ?? ServiceInstanceMode.PerCall;

            if (this.m_serviceMode == ServiceInstanceMode.Singleton)
            {
                this.m_instance = Activator.CreateInstance(behaviorType);
            }

            this.Name = behaviorAttribute?.Name ?? behaviorType.FullName;
        }
示例#2
0
        /// <summary>
        /// Creates the specified HttpHostContext
        /// </summary>
        public RestService(Object behaviorInstance)
        {
            this.m_serviceType = behaviorInstance.GetType();
            var behaviorAttribute = this.m_serviceType.GetCustomAttribute <ServiceBehaviorAttribute>();

            this.m_serviceMode = behaviorAttribute?.InstanceMode ?? ServiceInstanceMode.PerCall;

            if (this.m_serviceMode == ServiceInstanceMode.Singleton)
            {
                this.m_instance = behaviorInstance;
            }
            else
            {
                throw new InvalidOperationException("Cannot use this constructor with non-singleton services");
            }
            this.Name = behaviorAttribute?.Name ?? this.m_serviceType.FullName;
        }