Example #1
0
        /// <summary>
        /// Get a service factory to create and receive calls from a client.
        /// </summary>
        /// <typeparam name="TServiceContract">The type of the contract.</typeparam>
        /// <param name="channelId">The channel id.</param>
        /// <param name="implementationType">Type of the implementation.</param>
        /// <returns>Service factory</returns>
        /// <exception cref="System.ArgumentNullException">
        /// channelId
        /// or
        /// implementationType
        /// </exception>
        /// <exception cref="ChannelNotFoundException"></exception>
        public static IServiceFactory GetServiceFactory <TServiceContract>(String channelId, Type implementationType) where TServiceContract : IRemoteContract
        {
            if (string.IsNullOrEmpty(channelId))
            {
                throw new ArgumentNullException("channelId");
            }
            if (implementationType == null)
            {
                throw new ArgumentNullException("implementationType");
            }

            Channel channel = ChannelServices.GetChannelById(channelId);

            if (channel == null)
            {
                throw new ChannelNotFoundException(channelId);
            }

            IServiceFactory result = null;

            mFactoryLock.Lock();
            try
            {
                if (mFactories.Count > 0)
                {
                    foreach (ServiceFactory <IRemoteContract> factory in mFactories)
                    {
                        if (factory.ImplementationType.Equals(implementationType) && factory.ServiceContract.Equals(typeof(TServiceContract)) &&
                            factory.Channel.Equals(channel))
                        {
                            result = factory;
                            break;
                        }
                    }
                }
                if (result == null)
                {
                    result = new ServiceFactory <TServiceContract>(channelId, implementationType);
                    mFactories.Add(result);
                }
            }
            finally
            {
                mFactoryLock.Unlock();
            }

            return(result);
        }
Example #2
0
 /// <summary>
 /// Locks this instance.
 /// </summary>
 public void Lock()
 {
     mLock.Lock();
 }