Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot resolve parameter 'Volo.Abp.Caching.IDistributedCache #2839

Closed
mabusaa opened this issue Feb 16, 2020 · 5 comments
Closed

Cannot resolve parameter 'Volo.Abp.Caching.IDistributedCache #2839

mabusaa opened this issue Feb 16, 2020 · 5 comments

Comments

@mabusaa
Copy link

mabusaa commented Feb 16, 2020

I am trying to use Redis cache in .net core 3.1 , I am injecting the interface "IDistributedCache" in App service constructor , but I am receiving the below error :

---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Castle.Proxies.RequestStatusAppServiceProxy' can be invoked with the available services and parameters:
Cannot resolve parameter 'Volo.Abp.Caching.IDistributedCache1[System.Collections.Generic.List1

Module Configuration

private void ConfigureRedis(
            ServiceConfigurationContext context,
            IConfiguration configuration,
            IWebHostEnvironment hostingEnvironment)
        {

            context.Services.AddStackExchangeRedisCache(options =>
            {
                options.Configuration = configuration["Redis:Configuration"];
            });

            var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
            context.Services
                .AddDataProtection()
                .PersistKeysToStackExchangeRedis(redis, "Coo-Protection-Keys");
        }
@hikalkan
Copy link
Member

Are you injecting IDistributedCache<List<T>>? I suggest you to create another class to use for the cache and add List<T> inside it.
We didn't test well with generics as the IDistributedCache type parameter.
We can try to add this support if it is not supported, but first I want to understand if it works as I said.

@mabusaa
Copy link
Author

mabusaa commented Feb 16, 2020

My bad , Solved by adding [DependsOn(typeof(AbpCachingModule))]

@mabusaa mabusaa closed this as completed Feb 16, 2020
@mabusaa
Copy link
Author

mabusaa commented Feb 16, 2020

It will be great if this was added to documentation @hikalkan

@hikalkan
Copy link
Member

Startup templates already has this dependency, so didn't need to document. However, you are right, anyone may start with an empty project and want to use the caching module. Created an issue: #2842

@Jesn
Copy link

Jesn commented Aug 31, 2023

Are you injecting IDistributedCache<List<T>>? I suggest you to create another class to use for the cache and add List<T> inside it. We didn't test well with generics as the IDistributedCache type parameter. We can try to add this support if it is not supported, but first I want to understand if it works as I said.

 private readonly IDistributedCache<List<SpeedTestJobV2Args>, string> _speedTestJobArgCache;

 await _speedTestJobArgCache.SetAsync("SpeedTestJobV2Args",
                listArgs,
                new DistributedCacheEntryOptions()
                {
                    SlidingExpiration = TimeSpan.FromHours(2)
                }, token: cancellationToken);

Found the generated redis key as follows

c:System.Collections.Generic.List`1[[Rich.MagicNetWork.BackgroundJob.SpeedTest.Dto.SpeedTestJobV2Args, Rich.MagicNetWork.BackgroundJob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]],k:MagicNetwork:speedTestArgs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants