示例#1
0
        /// <summary>
        /// 注册服务
        /// </summary>
        /// <param name="context"></param>
        /// <param name="clazzes"></param>
        /// <param name="service"></param>
        /// <param name="property"></param>
        /// <returns></returns>
        public ServiceRegistrationImpl RegisterService(BundleContextImpl context, string[] clazzes, object service, IDictionary <string, object> properties)
        {
            if (service == null)
            {
                throw new ArgumentException("service");
            }

            int size = clazzes.Length;

            if (size == 0)
            {
                throw new ArgumentException("size");
            }

            /* copy the array so that changes to the original will not affect us. */
            IList copy = new ArrayList(size);

            // intern the strings and remove duplicates
            for (int i = 0; i < size; i++)
            {
                string clazz = string.Intern(clazzes[i]);
                if (!copy.Contains(clazz))
                {
                    copy.Add(clazz);
                }
            }

            clazzes = new string[copy.Count];
            copy.CopyTo(clazzes, 0);


            if (!(service is IServiceFactory))
            {
                //string invalidService = checkServiceClass(clazzes, service);
                //if (string.IsNullOrEmpty(invalidService))
                //{
                //    throw new ArgumentException("invalidService");
                //}
            }

            var registration = new ServiceRegistrationImpl(this, context, clazzes, service);

            registration.Register(properties);

            return(registration);
        }