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