| | | 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 System; |
| | | 5 | | using Microsoft.Extensions.DependencyInjection; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Configuration |
| | | 8 | | { |
| | | 9 | | public static class ServiceBuilderExtensions |
| | | 10 | | { |
| | | 11 | | public static void ConfigureServiceHostBase<TService>(this IServiceBuilder builder, Action<ServiceHostBase> func |
| | | 12 | | { |
| | 47 | 13 | | var serviceBuilder = builder as ServiceBuilder; |
| | 47 | 14 | | ServiceConfigurationDelegateHolder<TService> holder = serviceBuilder.ServiceProvider |
| | 47 | 15 | | .GetRequiredService<ServiceConfigurationDelegateHolder<TService>>(); |
| | 47 | 16 | | holder.AddConfigDelegate(func); |
| | 47 | 17 | | } |
| | | 18 | | |
| | | 19 | | public static void ConfigureServiceHostBase(this IServiceBuilder builder, Type serviceType, Action<ServiceHostBa |
| | | 20 | | { |
| | 2 | 21 | | if (serviceType is null) |
| | | 22 | | { |
| | 0 | 23 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(serviceType)) |
| | | 24 | | } |
| | | 25 | | |
| | 2 | 26 | | if (!serviceType.IsClass) |
| | | 27 | | { |
| | 1 | 28 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.ConfigureSe |
| | | 29 | | } |
| | | 30 | | |
| | 1 | 31 | | var serviceBuilder = builder as ServiceBuilder; |
| | 1 | 32 | | ServiceConfigurationDelegateHolder holder = (ServiceConfigurationDelegateHolder)serviceBuilder.ServiceProvid |
| | 1 | 33 | | .GetRequiredService(typeof(ServiceConfigurationDelegateHolder<>).MakeGenericType(serviceType)); |
| | 1 | 34 | | holder.AddConfigDelegate(func); |
| | 1 | 35 | | } |
| | | 36 | | |
| | | 37 | | public static void ConfigureAllServiceHostBase(this IServiceBuilder builder, Action<ServiceHostBase> func) |
| | | 38 | | { |
| | 11 | 39 | | var serviceBuilder = builder as ServiceBuilder; |
| | 11 | 40 | | AllServicesConfigurationDelegateHolder holder = serviceBuilder.ServiceProvider.GetRequiredService<AllService |
| | 11 | 41 | | holder.AddConfigDelegate(func); |
| | 11 | 42 | | } |
| | | 43 | | } |
| | | 44 | | } |