/// <summary> /// Creates an instance of a service with arguments /// </summary> /// <param name="constructorArgumentValues"> /// The constructor argument values. /// </param> /// <param name="cacheSuffix"> /// Optional additional caching suffix /// </param> /// <typeparam name="TService"> /// The type of the service to resolve /// </typeparam> /// <returns> /// The <see cref="TService"/>. /// </returns> /// <exception cref="Exception"> /// Throws an exception if service cannot be resolved /// </exception> public TService Instance <TService>(object[] constructorArgumentValues, string cacheSuffix = "") where TService : class, IRequestCachedService { //// We may need to manage separate instances of these services if the constructor arguments are different //// so that we can assert the values returned are what we expect. var suffix = string.Join(".", constructorArgumentValues.Select(x => x.ToString())); var cacheKey = $"{ServiceCacheKey(typeof(TService))}{suffix}{cacheSuffix}".GetHashCode().ToString(); return((TService)this._cache.RequestCache.GetCacheItem( cacheKey, () => ActivatorHelper.Instance <TService>(constructorArgumentValues))); }