0

I'm using a new .Net 8, and I'm trying to inject some service with a new way of keyed services, but unfortunately i cannot find FromKeyedServices, is not found, it's belong to Microsoft.Extensions.DependencyInjection namespace, i added this but still i don't see it.

using Microsoft.Extensions.DependencyInjection;

namespace SMSService.Persistence.ContextFactories
{
   public class ApplicationDbContextFactory<TDbContext>
    {
        private readonly IConfiguration _configuration;
        private readonly DbContextOptionsBuilder<TDbContext> _optionsBuilder;

        public ApplicationDbContextFactory(
            IConfiguration configuration,  [FromKeyedServices("Sql")] IDbContextOptionBuilder dbContextOptionBuilder ,           ILogger<ApplicationDbContextFactory<TDbContext>> logger)
        {

Can anyone help me

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Oleg Pro
  • 47
  • 5

1 Answers1

0

DI and FromKeyedServicesAttribute (since it's introduction in .NET 8 preview) in particular is part of the platform extensions which is not included by default in some of the project types (for example for Microsoft.NET.Sdk.Web SDK it will be included by default but for class library - will not).

For class library project install Microsoft.Extensions.DependencyInjection.Abstractions nuget.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132