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