Esempio n. 1
0
        public void Ctor_Test()
        {
            IAppServiceAdder   adder    = new AppServiceAdder();
            IServiceCollection services = new ServiceCollection();

            services = adder.AddServices(services);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
 }
        public void Ignore_Test()
        {
            IServiceCollection services = new ServiceCollection();
            IAppServiceAdder   adder    = new AppServiceAdder(new AppServiceScanOptions());

            services = adder.AddServices(services);

            services.ShouldContain(m => m.ServiceType == typeof(ITestContract));
            services.ShouldNotContain(m => m.ServiceType == typeof(IIgoreContract));
        }
Esempio n. 5
0
 /// <summary>
 /// 将应用程序服务添加到<see cref="IServiceCollection"/>
 /// 检索程序集,查找实现了<see cref="ITransientDependency"/>,<see cref="IScopeDependency"/>,<see cref="ISingletonDependency"/> 接口的所有服务,分别按生命周期类型进行添加
 /// </summary>
 public static IServiceCollection AddOSharp(this IServiceCollection services, IAppServiceAdder adder)
 {
     if (_added)
     {
         throw new InvalidOperationException("services.AddAppServices 扩展方法只能调用1次,不能多次调用。");
     }
     if (adder == null)
     {
         adder = new AppServiceAdder();
     }
     return(adder.AddServices(services));
 }