/// <summary> /// 添加依赖注入映射描述信息到服务映射信息集合中。 /// </summary> /// <param name="collection">服务映射信息集合。</param> /// <param name="serviceType">服务类型。</param> /// <param name="implementationInstance">服务实现实例。</param> /// <param name="lifetime">生命周期。</param> /// <returns></returns> public static IServiceCollection Add(this IServiceCollection collection, Type serviceType, object implementationInstance, LifetimeOption lifetime) { return(collection.TryAdd(ServiceDescriptor.Descriptor(serviceType, implementationInstance, lifetime))); }
/// <summary> /// 添加依赖注入映射描述信息到服务映射信息集合中。 /// </summary> /// <param name="collection">服务映射信息集合。</param> /// <param name="serviceType">服务类型。</param> /// <param name="implementationFactory">服务实现实例工厂。</param> /// <param name="lifetime">生命周期。</param> /// <returns></returns> public static IServiceCollection Add(this IServiceCollection collection, Type serviceType, Func <IServiceProvider, object> implementationFactory, LifetimeOption lifetime) { return(collection.TryAdd(ServiceDescriptor.Descriptor(serviceType, implementationFactory, lifetime))); }
/// <summary> /// 添加依赖注入映射描述信息到服务映射信息集合中。 /// </summary> /// <typeparam name="TService">泛型服务类型。</typeparam> /// <typeparam name="TImplementation">泛型实现类型。</typeparam> /// <param name="collection">服务映射信息集合。</param> /// <param name="lifetime">生命周期。</param> /// <returns></returns> public static IServiceCollection Add <TService, TImplementation>(this IServiceCollection collection, LifetimeOption lifetime) where TService : class where TImplementation : TService { return(collection.TryAdd(ServiceDescriptor.Descriptor <TService, TImplementation>(lifetime))); }