OrleansContrib / Orleans.Redis

Redis support packages for Orleans
MIT License
68 stars 22 forks source link

Unable to resolve service for type Orleans.Runtime.IPersistentState #40

Open onurcanyilmaz opened 2 years ago

onurcanyilmaz commented 2 years ago

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

[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 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.

wz172 commented 1 year ago

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

onurcanyilmaz commented 1 year ago

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 commented 1 year ago

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