| | | 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.Channels; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Configuration |
| | | 9 | | { |
| | | 10 | | public class ServiceConfigurationBuilder |
| | | 11 | | { |
| | 10 | 12 | | private readonly List<Action<ServiceConfigurationBuilder>> _configDelegates = new List<Action<ServiceConfigurati |
| | 10 | 13 | | private List<ServiceEndpointConfiguration> _endpoints = new List<ServiceEndpointConfiguration>(); |
| | | 14 | | private Type _serviceType; |
| | | 15 | | |
| | 10 | 16 | | public ServiceConfigurationBuilder(Type serviceType) |
| | | 17 | | { |
| | 10 | 18 | | _serviceType = serviceType; |
| | 10 | 19 | | } |
| | | 20 | | |
| | | 21 | | public void Configure(Action<ServiceConfigurationBuilder> configDelegate) |
| | | 22 | | { |
| | 13 | 23 | | _configDelegates.Add(configDelegate); |
| | 13 | 24 | | } |
| | | 25 | | |
| | | 26 | | public void AddServiceEndpoint(Type implementedContract, Binding binding, Uri address, Uri listenUri) |
| | | 27 | | { |
| | 2 | 28 | | _endpoints.Add(new ServiceEndpointConfiguration(implementedContract, binding, address, listenUri)); |
| | 2 | 29 | | } |
| | | 30 | | |
| | | 31 | | internal void ConfigureServiceBuilder(IServiceBuilder serviceBuilder) |
| | | 32 | | { |
| | 8 | 33 | | foreach (var configDelegate in _configDelegates) |
| | | 34 | | { |
| | 2 | 35 | | configDelegate(this); |
| | | 36 | | } |
| | | 37 | | |
| | 2 | 38 | | serviceBuilder.AddService(_serviceType); |
| | 8 | 39 | | foreach (var endpoint in _endpoints) |
| | | 40 | | { |
| | 2 | 41 | | serviceBuilder.AddServiceEndpoint(_serviceType, endpoint.Contract, endpoint.Binding, endpoint.Address, e |
| | | 42 | | } |
| | | 43 | | |
| | 2 | 44 | | _endpoints.Clear(); |
| | 2 | 45 | | } |
| | | 46 | | |
| | | 47 | | private struct ServiceEndpointConfiguration |
| | | 48 | | { |
| | | 49 | | public ServiceEndpointConfiguration(Type contract, Binding binding, Uri address, Uri listenUri) |
| | | 50 | | { |
| | 2 | 51 | | Contract = contract; |
| | 2 | 52 | | Binding = binding; |
| | 2 | 53 | | Address = address; |
| | 2 | 54 | | ListenUri = listenUri; |
| | 2 | 55 | | } |
| | | 56 | | |
| | 4 | 57 | | public Uri Address { get; set; } |
| | 4 | 58 | | public Binding Binding { get; set; } |
| | 4 | 59 | | public Type Contract { get; set; } |
| | 4 | 60 | | public Uri ListenUri { get; set; } |
| | | 61 | | } |
| | | 62 | | } |
| | | 63 | | } |