/// <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);
        }
Exemple #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);
        }
Exemple #3
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);
        }
Exemple #4
0
 /// <summary>
 /// 初始化一个<see cref="ServicesBuilder"/>类型的新实例
 /// </summary>
 public ServicesBuilder(ServiceBuildOptions options)
 {
     _options = options;
 }
Exemple #5
0
 /// <summary>
 /// 初始化一个<see cref="ServicesBuilder"/>类型的新实例
 /// </summary>
 public ServicesBuilder(ServiceBuildOptions options)
 {
     _options = options;
 }
Exemple #6
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;
        }