dependenciesinject

.NET 6 IServiceCollection dependency inject


I have written this code:

public static class DependencyInjection
{
    public static IServiceCollection AddInfrastructureShared(this IServiceCollection services, IConfiguration config)
    {
        services.Configure<MailSettings>(config.GetSection("MailSettings"));
        services.AddTransient<IDateTime, DateTimeService>();
        services.AddTransient<IEmailService, EmailService>();
        services.AddTransient<ICsvFileBuilder, CsvFileBuilder>();

        return services;
    }
}
//not find AddInfrastructureShared()
builder.Services.AddInfrastructureShared();

But VS tells me that it can not find AddInfrastructureShared(). It works well in .NET 5. After I upgraded to .NET 6, the error appeared.

Could anyone tell me how to fix it? Thank you.


Solution

  • restart vs. the vs will find the method. waste my time.