Orleans.Redis icon indicating copy to clipboard operation
Orleans.Redis copied to clipboard

Unable to resolve service for type Orleans.Runtime.IPersistentState

Open onurcanyilmaz opened this issue 2 years ago • 3 comments

I have aspnet core web api project, so I wanted to use Redis provider for clustering and storage.

Program.cs was like this

int db = 2;
string redisConnStr = "localhost:6379";

builder.Host.UseOrleans((host, builder) =>
{
    builder.AddRedisGrainStorage("RedisGrainStorage", optionsBuilder => optionsBuilder.Configure(options =>
    {
        options.ConnectionString = redisConnStr;
        options.UseJson = true;
        options.DatabaseNumber = db;
    }));

    builder.UseRedisClustering(options =>
    {
        options.ConnectionString = redisConnStr;
        options.Database = db;
    });

    builder.Configure<ClusterOptions>(options =>
    {
        options.ClusterId = "_basket_cluster";
        options.ServiceId = "_basket_service";
    });

    builder.Configure<EndpointOptions>(options =>
    {
        options.AdvertisedIPAddress = IPAddress.Loopback;
        options.GatewayListeningEndpoint = new IPEndPoint(IPAddress.Any, EndpointOptions.DEFAULT_GATEWAY_PORT);
        options.SiloListeningEndpoint = new IPEndPoint(IPAddress.Any, EndpointOptions.DEFAULT_SILO_PORT);
    });

    builder.ConfigureLogging(logging => logging.AddConsole());
});

builder.Services.AddTransient<IBasketActor, BasketActor>();

And I have a grain with name is BasketActor Then when I want to persistence my state with IPersistence<T>

[StorageProvider(ProviderName = "RedisGrainStorage")]
    public class BasketActor : Grain, IBasketActor
    {
        public BasketActor(
            [PersistentState("basket", "RedisGrainStorage")] IPersistentState<BasketState> basket
            )
        {
        }
    }

And I have a grain with name is BasketActor Then when I want to persistence my state with IPersistence<T> I am getting error this;

** Error while validating the service descriptor 'ServiceType:Basket.Actors.IBasketActor Lifetime: Transient ImplementationType: Basket.Actors.BasketActor': Unable to resolve service for type 'Orleans.Runtime.IPersistentState`1Basket.Actors.BasketState]' while attempting to activate 'Basket.Actors.BasketActor'.**

I've mentioned before in discord

Thanks.

onurcanyilmaz avatar Oct 17 '22 17:10 onurcanyilmaz

this builder.Services.AddTransient<IBasketActor, BasketActor>(); For what, Grain is not added that way.To use Part

wz172 avatar Nov 18 '22 10:11 wz172

this builder.Services.AddTransient<IBasketActor, BasketActor>(); For what, Grain is not added that way.To use Part

builder.Services.AddTransient<IBasketActor, BasketActor>();

OK. I removed that line but nothing was happened. Same issue occured. Have you ever else some solution?

By the way, Application parts has been removed for new version 7.0 source: https://learn.microsoft.com/en-us/dotnet/orleans/whats-new-in-orleans#packaging-changes

onurcanyilmaz avatar Nov 19 '22 23:11 onurcanyilmaz

I think this provider is very important, so we have to use upon Redis properly by Orleans Any news?

onurcanyilmaz avatar Jan 14 '23 12:01 onurcanyilmaz