| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using Microsoft.Extensions.DependencyInjection; |
| | | 5 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 6 | | using Microsoft.Extensions.Options; |
| | | 7 | | using System.IO; |
| | | 8 | | using System; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.Configuration |
| | | 11 | | { |
| | | 12 | | public static class ConfigurationManagerExtensions |
| | | 13 | | { |
| | | 14 | | public static IServiceCollection AddServiceModelConfigurationManagerFile(this IServiceCollection builder, string |
| | | 15 | | { |
| | 40 | 16 | | if (!File.Exists(path)) { throw new FileNotFoundException(SR.Format(SR.FileNotFound, path)); } |
| | 40 | 17 | | using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read)) |
| | | 18 | | { |
| | 40 | 19 | | if (!fs.CanRead) { throw new IOException(SR.Format(SR.CannotAccessFile, path)); } |
| | 40 | 20 | | } |
| | | 21 | | |
| | 40 | 22 | | builder.TryAddSingleton<IConfigurationHolder, ConfigurationHolder>(); |
| | 40 | 23 | | builder.TryAddSingleton<IBindingFactory, BindingFactory>(); |
| | 80 | 24 | | builder.AddSingleton<IConfigureOptions<ServiceModelOptions>>(ctx => new ConfigurationManagerServiceModelOpti |
| | | 25 | | |
| | 40 | 26 | | return builder; |
| | | 27 | | } |
| | | 28 | | } |
| | | 29 | | } |