示例#1
0
        public NuGetApiOptions(IServiceCollection services)
        {
            Services = services ?? throw new ArgumentNullException(nameof(services));

            var hostEnvironment = services.FirstOrDefault(x => hostEnvironmentTypes.Any(he => he == x.ServiceType.FullName))?.ImplementationInstance;

            EnvironmentName = (string)hostEnvironment.GetType().GetProperty("EnvironmentName").GetValue(hostEnvironment);

            var configurationDescriptors = services.Where(x => x.ServiceType == typeof(IConfiguration));

            if (configurationDescriptors.Any(x => x.ImplementationInstance != null))
            {
                Configuration = (IConfiguration)configurationDescriptors.First(x => x.ImplementationInstance != null).ImplementationInstance;
            }
            else if (configurationDescriptors.Any(x => x.ImplementationFactory != null))
            {
                var configurationDescriptor = configurationDescriptors.First(x => x.ImplementationFactory != null);
                var instance = configurationDescriptor.ImplementationFactory(null);
                Configuration = (IConfiguration)instance;
            }

            if (Configuration != null)
            {
                var options = new PackageFeedOptions();
                Configuration.Bind(options);
                Options = options;
            }
        }
示例#2
0
 public PackageDeletionService(
     IPackageService packages,
     IPackageStorageService storage,
     IOptionsSnapshot <PackageFeedOptions> options,
     ILogger <PackageDeletionService> logger)
 {
     _packages = packages ?? throw new ArgumentNullException(nameof(packages));
     _storage  = storage ?? throw new ArgumentNullException(nameof(storage));
     _options  = options?.Value ?? throw new ArgumentNullException(nameof(options));
     _logger   = logger ?? throw new ArgumentNullException(nameof(logger));
 }