Beispiel #1
0
 /// <summary>
 /// Initializes a new System.Data.Services.BaseServiceProvider instance.
 /// </summary>
 /// <param name="metadata">Metadata for this provider.</param>
 /// <param name="dataServiceInstance">data service instance.</param>
 protected BaseServiceProvider(MetadataCacheItem metadata, object dataServiceInstance)
 {
     WebUtil.CheckArgumentNull(metadata, "metadata");
     WebUtil.CheckArgumentNull(dataServiceInstance, "dataServiceInstance");
     this.metadata = metadata;
     this.dataServiceInstance = dataServiceInstance;
 }
Beispiel #2
0
        /// <summary>Adds a new cache item, and returns the item that is put in the cache.</summary>
        /// <param name="serviceType">Type of service with metadata being cached.</param>
        /// <param name="dataContextInstance">
        /// Data context instance being cached, possibly segmenting the cache
        /// space for <paramref name="serviceType"/>.
        /// </param>
        /// <param name="item">Item being added.</param>
        /// <returns>The item being put in the cache (possibly an existing one).</returns>
        /// <remarks>This method is thread-safe but not re-entrant.</remarks>
        internal static MetadataCacheItem AddCacheItem(Type serviceType, object dataContextInstance, MetadataCacheItem item)
        {
            Debug.Assert(serviceType != null, "serviceType != null");
            Debug.Assert(dataContextInstance != null, "dataContextInstance != null");
            Debug.Assert(item != null, "item != null");

            MetadataCacheKey  key = new MetadataCacheKey(serviceType, dataContextInstance as ObjectContext);
            MetadataCacheItem result;

            cacheLock.EnterWriteLock();
            try
            {
                // If another thread beat the current thread, we return the
                // previously created item, which has a higher chance of
                // having survived a garbage collection already.
                if (!cache.TryGetValue(key, out result))
                {
                    cache.Add(key, item);
                    result = item;
                }
            }
            finally
            {
                cacheLock.ExitWriteLock();
            }

            Debug.Assert(result != null, "result != null -- a null item is never returned.");
            Debug.Assert(
                result == TryLookup(serviceType, dataContextInstance),
                "result == TryLookup(serviceType, dataContextInstance) -- instance from cache is being returned.");

            return(result);
        }
 /// <summary>
 /// Initializes a new System.Data.Services.ReflectionServiceProvider instance.
 /// </summary>
 /// <param name="metadata">Metadata for this provider.</param>
 /// <param name="dataServiceInstance">data service instance.</param>
 internal ReflectionServiceProvider(MetadataCacheItem metadata, object dataServiceInstance)
     : base(metadata, dataServiceInstance)
 {
 }