| | | 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 System.Collections.Generic; |
| | | 6 | | using CoreWCF.Description; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Configuration |
| | | 9 | | { |
| | | 10 | | public class ServiceOptions |
| | | 11 | | { |
| | 1152 | 12 | | internal ServiceOptions() { } |
| | | 13 | | |
| | 1163 | 14 | | public ServiceDebugBehavior DebugBehavior { get; } = new ServiceDebugBehavior(); |
| | | 15 | | |
| | 784 | 16 | | public ICollection<Uri> BaseAddresses { get; } = new List<Uri>(); |
| | | 17 | | } |
| | | 18 | | |
| | | 19 | | internal class ServiceOptions<TService> : ServiceOptions where TService : class |
| | | 20 | | { |
| | | 21 | | private ServiceHostObjectModel<TService> _serviceHost; |
| | | 22 | | internal ServiceOptions(ServiceHostObjectModel<TService> serviceHost) |
| | | 23 | | { |
| | | 24 | | _serviceHost = serviceHost; |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | internal void ApplyOptions(ServiceConfigurationDelegateHolder configDelegateHolder) |
| | | 28 | | { |
| | | 29 | | bool optionsDelegateProvided = configDelegateHolder.ApplyOptions(this); |
| | | 30 | | if (optionsDelegateProvided) |
| | | 31 | | { |
| | | 32 | | ApplyOptionsToServiceHost(); |
| | | 33 | | } |
| | | 34 | | else |
| | | 35 | | { |
| | | 36 | | SetNoOptionsDelegateDefaults(); |
| | | 37 | | } |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | private void ApplyOptionsToServiceHost() |
| | | 41 | | { |
| | | 42 | | _serviceHost.Description.Behaviors.Remove<ServiceDebugBehavior>(); |
| | | 43 | | _serviceHost.Description.Behaviors.Add(DebugBehavior); |
| | | 44 | | if (BaseAddresses.Count > 0) |
| | | 45 | | { |
| | | 46 | | _serviceHost.InternalBaseAddresses.Clear(); |
| | | 47 | | foreach (Uri baseAddress in BaseAddresses) |
| | | 48 | | { |
| | | 49 | | _serviceHost.InternalBaseAddresses.Add(baseAddress); |
| | | 50 | | } |
| | | 51 | | } |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | private void SetNoOptionsDelegateDefaults() |
| | | 55 | | { |
| | | 56 | | // Enabling the debug page is a change in behavior which might take people by surprise |
| | | 57 | | // This code runs when not using the new options overload of AddService so only apps |
| | | 58 | | // which use the options overload will have the HttpHelpPageEnabled enabled by default. |
| | | 59 | | // That requires a code change so change is expected. |
| | | 60 | | DebugBehavior.HttpHelpPageEnabled = false; |
| | | 61 | | } |
| | | 62 | | } |
| | | 63 | | } |