VahidN / EFSecondLevelCache.Core

Entity Framework Core Second Level Caching Library
Apache License 2.0
326 stars 51 forks source link

query.Cacheable(debugInfo) throws error #24

Closed santubangalore closed 5 years ago

santubangalore commented 5 years ago

Summary of the issue

I am faced with the  problem of query.Cacheable(debugInfo) thrwing error.

Environment

VS 2017 Pro, dot net core 2.0
The in-use version:
Operating system: 
IDE: (e.g. Visual Studio 2015): Visual tudio 2017, Dot net core 2.0

Example code/Steps to reproduce:

**I have created extension method ToCacheList in a class.

next i am invoking the method with iqueryable object.

var q = from c in this.Query() select c;

return await q.ToCacheList();**

paste your core code

public static async Task<IEnumerable> ToCacheList(this IQueryable query) { EFCacheDebugInfo debugInfo = new EFCacheDebugInfo(); var result = redisOn ? await query.Cacheable(debugInfo).ToListAsync() : await query.ToListAsync(); return result; }

Output:

Exception message:
System.InvalidOperationException: Unable to resolve service for type 'CacheManager.Core.ICacheManager`1[System.Object]' while attempting to activate 'EFSecondLevelCache.Core.EFCacheServiceProvider'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(Type serviceType, Type implementationType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type serviceType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateServiceAccessor(Type serviceType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   at EFSecondLevelCache.Core.EFCachedQueryExtensions.configureProviders()
VahidN commented 5 years ago
Unable to resolve service for type 'CacheManager.Core.ICacheManager`1[System.Object]'

means you have not registered the ICacheManager service and the in use IoC Container doesn't know how/where to find it. follow this sample for more info. You should use addInMemoryCacheServiceProvider or addRedisCacheServiceProvider after calling AddEFSecondLevelCache.

Also you should use IQueryable<TType> query. Take a look at this file to see how different overloads of Cacheable are defined.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related problems.