Ejemplo n.º 1
0
        /// <summary>
        /// 将当前服务创建为
        /// </summary>
        /// <returns>服务映射集合</returns>
        public IServiceCollection Build()
        {
            IServiceCollection services = new ServiceCollection();
            ServiceBuildOptions options = _options;
            try
            {
                //添加即时生命周期类型的映射
                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);

            }
            catch (ReflectionTypeLoadException ex)
            {
                Exception[] loadExs = ex.LoaderExceptions;
                throw;
            }
            return services;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 将当前服务创建为
        /// </summary>
        /// <returns>服务映射集合</returns>
        public IServiceCollection Build()
        {
            IServiceCollection services = new ServiceCollection();
            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;
        }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 创建依赖注入服务映射信息集合
        /// </summary>
        /// <returns>服务映射信息集合</returns>
        private IServiceCollection Create(ServiceBuildOptions options)
        {
            IServiceCollection services = new ServiceCollection();
            OSharpContext.IocRegisterServices = services;

            //添加即时生命周期类型的映射
            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;
        }