OrleansContrib/Orleans.Providers.MongoDB

AddMongoDBGrainStorage

cwoodall-arch opened this issue · 5 comments

This is probably related to the breaking change, but I can't seem to resolve the issue. My silo works fine without AddMongoDBGrainStorage, but it fails with the following error when I add it:

Cannot resolve scoped service 'Microsoft.Extensions.Options.IOptionsSnapshot`1[Orleans.Providers.MongoDB.Configuration.MongoDBGrainStorageOptions]' from root provider.

Here is my silo if it helps:

public static IHostBuilder CreateOrleansMongoHost(string[] args) =>

        Host.CreateDefaultBuilder(args)
        .UseOrleans((host, config) =>
        {
            config.UseMongoDBClient(host.Configuration.GetSection("MongoStorage").Value)
            .Configure<ClusterOptions>(options =>
            {
                options.ClusterId = "TestCluster";
                options.ServiceId = "TestService";
            })
            .UseMongoDBClustering(options =>
            {
                options.DatabaseName = "Test";
                options.Strategy = MongoDBMembershipStrategy.SingleDocument;
            })
            .UseMongoDBReminders(options =>
            {
                options.DatabaseName = "Test";
            })
            .AddMongoDBGrainStorage("TestStore", options =>
            {
                options.DatabaseName = "Test";
                options.CreateShardKeyForCosmos = false;
                options.ConfigureJsonSerializerSettings = settings =>
                {
                    settings.NullValueHandling = NullValueHandling.Include;
                    settings.ObjectCreationHandling = ObjectCreationHandling.Replace;
                    settings.DefaultValueHandling = DefaultValueHandling.Populate;
                };
            })
            .ConfigureEndpoints(Dns.GetHostName(), 11111, 30000)
            .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(ITestGrain).Assembly).WithReferences());
        })
        .ConfigureWebHostDefaults(config =>
        {
            config.UseStartup<Startup>();
        })
        .ConfigureLogging(config =>
        {
            config.AddConsole();
        });

Perhaps an issue with the custom name "TestStore"? Have you tried the "asDefault" variant?

Hi. I just tried using the AddMongoDBGrainStorageasDefault method, and I get the same result.

I cannot reproduce it, I need a sample

It works fine in localhost, but got the same exception in Azure Cosmos DB

System.InvalidOperationException: Cannot resolve scoped service 'Microsoft.Extensions.Options.IOptionsSnapshot`1[Orleans.Providers.MongoDB.Configuration.MongoDBGrainStorageOptions]' from root provider.

Then I found this issue, so I clone the source code and replace IOptionsSnapshot to IOptionsMonitor, and it just works.

PS. English is not my native language.

Yes, it should be the same fix as here: https://github.com/OrleansContrib/Orleans.CosmosDB/pull/43/files

@GundamBox, could you submit a PR?