Esempio n. 1
0
        /// <summary>
        /// 创建单例类型的映射并尝试到服务映射集合中
        /// </summary>
        /// <param name="collection">服务映射集合</param>
        /// <param name="serviceType">服务类型</param>
        /// <param name="factory">服务实现类型实例工厂</param>
        /// <returns></returns>
        public static IServiceCollection TryAddSingleton(this IServiceCollection collection, Type serviceType, Func <IServiceProvider, object> factory)
        {
            ServiceDescriptor descriptor = ServiceDescriptor.Singleton(serviceType, factory);

            return(collection.TryAdd(descriptor));
        }
Esempio n. 2
0
        /// <summary>
        /// 创建单例类型的映射并尝试到服务映射集合中
        /// </summary>
        /// <param name="collection">服务映射集合</param>
        /// <param name="serviceType">服务类型</param>
        /// <param name="implementationType">服务实现类型</param>
        /// <returns></returns>
        public static IServiceCollection TryAddSingleton(this IServiceCollection collection, Type serviceType, Type implementationType)
        {
            ServiceDescriptor descriptor = ServiceDescriptor.Singleton(serviceType, implementationType);

            return(collection.TryAdd(descriptor));
        }