Пример #1
0
        /// <summary>
        /// 解析指定类型的服务实例
        /// </summary>
        /// <param name="serviceType">服务类型</param>
        public object GetService(Type serviceType)
        {
            Check.NotNull(_services, nameof(_services));
            Check.NotNull(_provider, nameof(_provider));

            IScopedServiceResolver scopedResolver = _provider.GetService <IScopedServiceResolver>();

            if (scopedResolver != null && scopedResolver.ResolveEnabled)
            {
                return(scopedResolver.GetService(serviceType));
            }
            return(_provider.GetService(serviceType));
        }
Пример #2
0
        /// <summary>
        /// 解析指定类型的服务实例
        /// </summary>
        public T GetService <T>()
        {
            _services.CheckNotNull(nameof(_services));
            _provider.CheckNotNull(nameof(_provider));

            IScopedServiceResolver scopedResolver = _provider.GetService <IScopedServiceResolver>();

            if (scopedResolver != null && scopedResolver.ResolveEnabled)
            {
                return(scopedResolver.GetService <T>());
            }
            return(_provider.GetService <T>());
        }