| | | 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 | | using CoreWCF.Runtime; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Configuration |
| | | 10 | | { |
| | | 11 | | internal class ServiceConfiguration<TService> : IServiceConfiguration<TService> where TService : class |
| | | 12 | | { |
| | | 13 | | private readonly ServiceBuilder _serviceBuilder; |
| | | 14 | | private readonly IServiceProvider _services; |
| | | 15 | | private List<IServiceDispatcher> _dispatchers; |
| | 585 | 16 | | private object _lock = new object(); |
| | | 17 | | |
| | 585 | 18 | | public ServiceConfiguration(ServiceBuilder serviceBuilder, IServiceProvider services) |
| | | 19 | | { |
| | 585 | 20 | | _serviceBuilder = serviceBuilder; |
| | 585 | 21 | | _services = services; |
| | 585 | 22 | | } |
| | | 23 | | |
| | 586 | 24 | | public Type ServiceType => typeof(TService); |
| | | 25 | | |
| | 2341 | 26 | | public List<ServiceEndpointConfiguration> Endpoints { get; } = new List<ServiceEndpointConfiguration>(); |
| | | 27 | | |
| | | 28 | | public List<IServiceDispatcher> GetDispatchers() |
| | | 29 | | { |
| | 609 | 30 | | if (_dispatchers == null) |
| | | 31 | | { |
| | | 32 | | // The services can't be Open'd until after ASP.NET Core is running and listening for requests. The Open |
| | | 33 | | // is started and allowed to run in the background. If a request comes in before the dispatchers have fi |
| | | 34 | | // being built, there are multiple problems which can occur such as adding an endpoint twice, or concurr |
| | | 35 | | // modification of collections, or trying to modify the service host after it has been opened. |
| | | 36 | | // This double check lock ensures this doesn't happen. |
| | 583 | 37 | | lock (_lock) |
| | | 38 | | { |
| | 583 | 39 | | if (_dispatchers == null) |
| | | 40 | | { |
| | 583 | 41 | | _dispatchers = DispatcherBuilder.BuildDispatcher<TService>(this, _services); |
| | | 42 | | } |
| | 573 | 43 | | } |
| | | 44 | | } |
| | | 45 | | |
| | 599 | 46 | | return _dispatchers; |
| | | 47 | | } |
| | | 48 | | } |
| | | 49 | | } |