< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Dispatcher.SingletonInstanceContextProvider
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/SingletonInstanceContextProvider.cs
Line coverage
80%
Covered lines: 21
Uncovered lines: 5
Coverable lines: 26
Total lines: 94
Line coverage: 80.7%
Branch coverage
92%
Covered branches: 13
Total branches: 14
Branch coverage: 92.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
GetExistingInstanceContext(...)100%44100%
InitializeInstanceContext(...)100%110%
IsIdle(...)100%110%
NotifyIdle(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/SingletonInstanceContextProvider.cs

#LineLine coverage
 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
 4using System;
 5using CoreWCF.Channels;
 6
 7namespace CoreWCF.Dispatcher
 8{
 9    internal class SingletonInstanceContextProvider : InstanceContextProviderBase
 10    {
 11        private InstanceContext _singleton;
 12        private readonly object _thisLock;
 13
 14        internal SingletonInstanceContextProvider(DispatchRuntime dispatchRuntime)
 12515            : base(dispatchRuntime)
 16        {
 12517            _thisLock = new object();
 12518        }
 19
 20        internal InstanceContext SingletonInstance
 21        {
 22            get
 23            {
 18324                if (_singleton == null)
 25                {
 8226                    lock (_thisLock)
 27                    {
 8228                        if (_singleton == null)
 29                        {
 8230                            InstanceContext instanceContext = DispatchRuntime.SingletonInstanceContext;
 31
 8232                            if (instanceContext == null)
 33                            {
 034                                instanceContext = new InstanceContext(DispatchRuntime.ChannelDispatcher.Host, false);
 035                                instanceContext.OpenAsync().GetAwaiter().GetResult();
 36                            }
 8237                            else if (instanceContext.State != CommunicationState.Opened)
 38                            {
 39                                // we need to lock against the instance context for open since two different endpoints c
 40                                // share the same instance context, but different providers. So the provider lock does n
 41                                // the open process
 8242                                lock (instanceContext.ThisLock)
 43                                {
 8244                                    if (instanceContext.State != CommunicationState.Opened)
 45                                    {
 8246                                        instanceContext.OpenAsync().GetAwaiter().GetResult();
 47                                    }
 8248                                }
 49                            }
 50
 51                            //Set the IsUsercreated flag to false for singleton mode even in cases when users create the
 8252                            instanceContext.IsUserCreated = false;
 53
 54                            //Delay assigning the potentially newly created InstanceContext (till after its opened) to t
 55                            //to ensure that it is opened only once.
 8256                            _singleton = instanceContext;
 57                        }
 8258                    }
 59                }
 18360                return _singleton;
 61            }
 62        }
 63
 64        #region IInstanceContextProvider Members
 65
 66        public override InstanceContext GetExistingInstanceContext(Message message, IContextChannel channel)
 67        {
 12968            ServiceChannel serviceChannel = GetServiceChannelFromProxy(channel);
 12969            if (serviceChannel != null && serviceChannel.HasSession)
 70            {
 5471                SingletonInstance.BindIncomingChannel(serviceChannel);
 72            }
 12973            return SingletonInstance;
 74        }
 75
 76        public override void InitializeInstanceContext(InstanceContext instanceContext, Message message, IContextChannel
 77        {
 78            //no-op
 079        }
 80
 81        public override bool IsIdle(InstanceContext instanceContext)
 82        {
 83            //By default return false
 084            return false;
 85        }
 86
 87        public override void NotifyIdle(Action<InstanceContext> callback, InstanceContext instanceContext)
 88        {
 89            //no-op
 090        }
 91
 92        #endregion
 93    }
 94}