79121836

Date: 2024-10-24 12:21:39
Score: 0.5
Natty:
Report link

As per the https://autofac.readthedocs.io/en/latest/integration/netcore.html#quick-start page, the simplest, and most correct method is this:

// Generate a ServiceCollection to directly add elements to.
var serviceCollection = new ServiceCollection();

// Add the HTTP Client as per the extension.
serviceCollection.AddHttpClient();
serviceCollection.AddHttpClient<IUserService, UserService>();
serviceCollection.AddHttpClient<IPostService, PostService>();

// Build the ContainerBuilder.
var containerBuilder = new ContainerBuilder();

// Populate the builder from the ServiceCollection.
containerBuilder.Populate(serviceCollection);

// Continue with the AutoFac registrations after this point.
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Perringaiden