예제 #1
0
        /// <summary>
        /// 将OSharp服务,各个<see cref="OsharpPack"/>模块的服务添加到服务容器中
        /// </summary>
        public static IServiceCollection AddOSharp(this IServiceCollection services, Action <IOSharpBuilder> builderAction = null, AppServiceScanOptions scanOptions = null)
        {
            Check.NotNull(services, nameof(services));

            IOSharpBuilder builder = new OSharpBuilder();

            if (builderAction != null)
            {
                builderAction(builder);
            }
            OSharpPackManager manager = new OSharpPackManager(builder, new AppDomainAllAssemblyFinder());

            manager.LoadPacks(services);
            services.AddSingleton(provider => manager);
            if (scanOptions == null)
            {
                scanOptions = new AppServiceScanOptions();
            }
            services = new AppServiceAdder(scanOptions).AddServices(services);
            if (builder.OptionsAction != null)
            {
                services.Configure(builder.OptionsAction);
            }
            return(services);
        }
예제 #2
0
 /// <summary>
 /// 将应用程序服务添加到<see cref="IServiceCollection"/>
 /// 检索程序集,查找实现了<see cref="ITransientDependency"/>,<see cref="IScopeDependency"/>,<see cref="ISingletonDependency"/> 接口的所有服务,分别按生命周期类型进行添加
 /// </summary>
 public static IServiceCollection AddOSharp(this IServiceCollection services, AppServiceScanOptions scanOptions = null)
 {
     if (scanOptions == null)
     {
         scanOptions = new AppServiceScanOptions();
     }
     services = new AppServiceAdder(scanOptions).AddServices(services);
     ServiceLocator.Instance.TrySetServiceCollection(services);
     return(services);
 }
예제 #3
0
 /// <summary>
 /// 初始化一个<see cref="AppServiceAdder"/>类型的新实例
 /// </summary>
 public AppServiceAdder(AppServiceScanOptions options)
 {
     _options = options;
 }
예제 #4
0
        /// <summary>
        /// 将应用程序服务添加到<see cref="IServiceCollection"/>
        /// 检索程序集,查找实现了<see cref="ITransientDependency"/>,<see cref="IScopeDependency"/>,<see cref="ISingletonDependency"/> 接口的所有服务,分别按生命周期类型进行添加
        /// </summary>
        public static IServiceCollection AddOSharp(this IServiceCollection services, Action <OSharpOptions> configureOptions, AppServiceScanOptions scanOptions = null)
        {
            Check.NotNull(services, nameof(services));
            Check.NotNull(configureOptions, nameof(configureOptions));

            services.AddOSharp(scanOptions);
            services.Configure(configureOptions);
            return(services);
        }