autofac/Autofac.Extensions.DependencyInjection

net8.0 used Orleans project, then replaced the container with Autofac, Host failed to start

wz172 opened this issue · 7 comments

wz172 commented

Autofac.Core.DependencyResolutionException:“An exception was thrown while activating λ:Microsoft.Extensions.Hosting.IHostedService[] -> Orleans.Hosting.SiloHostedService -> Orleans.Runtime.Silo.”

Describe the Bug

InvalidOperationException: This service provider doesn't support keyed services.

Steps to Reproduce

Use the HelloWord example in Orleans, then replace the container with Autofac

using Autofac.Extensions.DependencyInjection;
using Autofac;
using HelloWorld;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Reflection;

var hostBuilder = new HostBuilder();

hostBuilder.UseServiceProviderFactory(new AutofacServiceProviderFactory());
hostBuilder.ConfigureContainer<ContainerBuilder>((hostContext, container) =>
{
 
});


// Configure the host
using var host = hostBuilder
    .UseOrleans(builder => builder.UseLocalhostClustering())
   .Build();

// Start the host
await host.StartAsync();

// Get the grain factory
var grainFactory = host.Services.GetRequiredService<IGrainFactory>();

// Get a reference to the HelloGrain grain with the key "friend"
var friend = grainFactory.GetGrain<IHelloGrain>("friend");

// Call the grain and print the result to the console
var result = await friend.SayHello("Good morning!");
Console.WriteLine($"""

    {result}

    """);

Console.WriteLine("Orleans is running.\nPress Enter to terminate...");
Console.ReadLine();
Console.WriteLine("Orleans is stopping...");

await host.StopAsync();

Expected Behavior

Exception with Stack Trace

Put the exception with stack trace here.

Dependency Versions

Autofac: Latest edition.

Additional Info

wz172 commented

If only I knew.Thank you very much for the solution

what was your solution?

Oh, I see the newest version of Autofac does not support net8 keyed services. Got errors with libraries that are using net8 keyed services

Expecting this to be resolved imminently: #112

Oh, thanks!

Expecting this to be resolved imminently: autofac/Autofac.Extensions.DependencyInjection#112

wz172 commented

Oh, I see the newest version of Autofac does not support net8 keyed services. Got errors with libraries that are using net8 keyed services
Yes, autofac does not implement the new net.8 IkeyServiceProvider interface, and whether the injection is a KeyServicer attribute, so there will be bugs in the injection and acquisition of the implementation Service.At present, however, Autofac does not seem to be adapted

tillig commented

To be clear, Autofac core does not implement the Microsoft IServiceProvider interface. You're looking at the wrong library/release list. Watch for changes in Autofac.Extensions.DependencyInjection - that's where you'd see keyed service features added. As such, you may have missed that we released keyed services two days ago with Autofac.Extensions.DependencyInjection 9.0.0.

To help folks disambiguate/look in the correct place, I'm going to transfer this issue to the correct repo.