예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <see cref="IServiceLocator.GetAllInstances(Type)" />
        public IEnumerable <object> GetAllInstances(Type serviceType)
        {
            if (serviceType == null)
            {
                throw new ArgumentNullException("serviceType");
            }

            IEnumerable <object> result = null;

            ServiceActivationException exceptionToThrow = null;

            try
            {
                result = this.OnGetAllInstances(serviceType);

                if (result == null)
                {
                    exceptionToThrow = new ServiceActivationException(serviceType,
                                                                      null);
                }
            }
            catch (Exception ex)
            {
                exceptionToThrow = new ServiceActivationException(serviceType,
                                                                  null,
                                                                  ex);
            }

            if (exceptionToThrow != null)
            {
                throw exceptionToThrow;
            }

            return(result.Select(s => !DBNull.Value.Equals(s) ? s : null)
                   .OfType <object>());
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <see cref="IServiceLocator.GetInstance(Type, object)" />
        public object GetInstance(Type serviceType, object key)
        {
            if (serviceType == null)
            {
                throw new ArgumentNullException("serviceType");
            }

            object result = null;

            ServiceActivationException exceptionToThrow = null;

            try
            {
                result = ParseValue(this.OnGetInstance(serviceType,
                                                       ParseValue(key)));

                if (result == null)
                {
                    exceptionToThrow = new ServiceActivationException(serviceType,
                                                                      key);
                }
            }
            catch (Exception ex)
            {
                exceptionToThrow = new ServiceActivationException(serviceType,
                                                                  key,
                                                                  ex);
            }

            if (exceptionToThrow != null)
            {
                throw exceptionToThrow;
            }

            return(result);
        }