Exemple #1
0
        /// <summary>
        /// Disposes of a single component instance, matching a given registration.
        /// </summary>
        /// <param name="registration">Registration.</param>
        /// <param name="instanceCache">Instance cache.</param>
        protected virtual void Dispose(IServiceRegistration registration, ICachesResolvedServiceInstances instanceCache)
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }
            if (instanceCache == null)
            {
                throw new ArgumentNullException(nameof(instanceCache));
            }

            object instance;

            if (!instanceCache.TryGet(registration, out instance))
            {
                return;
            }

            if (!(instance is IDisposable))
            {
                return;
            }

            ((IDisposable)instance).Dispose();
        }
        /// <summary>
        /// Attempts to get a service/component instance from the cache, where it matches the given registration.
        /// </summary>
        /// <returns><c>true</c>, if the component was resolved from the cache, <c>false</c> otherwise.</returns>
        /// <param name="registration">Registration.</param>
        /// <param name="cachedInstance">Cached instance.</param>
        protected virtual bool TryGetFromCache(IServiceRegistration registration, out object cachedInstance)
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }


            if (!registration.Cacheable)
            {
                cachedInstance = null;
                return(false);
            }

            return(cache.TryGet(registration, out cachedInstance));
        }