/// <summary> /// 将应用程序服务添加到<see cref="IServiceCollection"/> /// 检索程序集,查找实现了<see cref="ITransientDependency"/>,<see cref="IScopeDependency"/>,<see cref="ISingletonDependency"/> 接口的所有服务,分别按生命周期类型进行添加 /// </summary> public static IServiceCollection AddOSharp(this IServiceCollection services, AppServiceAdderOptions options = null) { if (_added) { throw new InvalidOperationException("services.AddAppServices 扩展方法只能调用1次,不能多次调用。"); } if (options == null) { options = new AppServiceAdderOptions(); } return(new AppServiceAdder(options).AddServices(services)); }
public void Ctor_Test() { AppServiceAdderOptions options = new AppServiceAdderOptions(); options.TransientTypeFinder.ShouldNotBeNull(); options.ScopedTypeFinder.ShouldNotBeNull(); options.SingletonTypeFinder.ShouldNotBeNull(); (options.TransientTypeFinder is TransientDependencyTypeFinder).ShouldBeTrue(); (options.ScopedTypeFinder is ScopedDependencyTypeFinder).ShouldBeTrue(); (options.SingletonTypeFinder is SingletonDependencyTypeFinder).ShouldBeTrue(); }