Exemple #1
0
        /// <summary>
        /// 将当前服务创建为
        /// </summary>
        /// <returns>服务映射集合</returns>
        public IServiceCollection Build()
        {
            IServiceCollection services = new ServiceCollection();
            OSkyContext.IocRegisterServices = services;
            ServiceBuildOptions options = _options;

            //添加即时生命周期类型的映射
            Type[] dependencyTypes = options.TransientTypeFinder.FindAll();
            AddTypeWithInterfaces(services, dependencyTypes, LifetimeStyle.Transient);

            //添加局部生命周期类型的映射
            dependencyTypes = options.ScopeTypeFinder.FindAll();
            AddTypeWithInterfaces(services, dependencyTypes, LifetimeStyle.Scoped);

            //添加单例生命周期类型的映射
            dependencyTypes = options.SingletonTypeFinder.FindAll();
            AddTypeWithInterfaces(services, dependencyTypes, LifetimeStyle.Singleton);

            //全局服务
            AddGlobalTypes(services);

            return services;
        }
Exemple #2
0
 /// <summary>
 /// Creates a new object that is a copy of the current instance.
 /// </summary>
 /// <returns>
 /// A new object that is a copy of this instance.
 /// </returns>
 public IServiceCollection Clone()
 {
     ServiceCollection collection = new ServiceCollection();
     foreach (ServiceDescriptor descriptor in this)
     {
         collection.Add(descriptor);
     }
     return collection;
 }