Why in extension method I don't have access to some other IServiceCollection extensions in .net Core?

Mohammad Taherian

In program.cs I can do

services.Configure<Blah>(configuration.GetSection("foo"));

But when I create an extension method for IServiceCollection there is no Configure method to use

namespace Microsoft.Extensions.DependencyInjection;

public static class ServiceExtensions
{
    public static IServiceCollection AddMyServices(this IServiceCollection services, IConfiguration config)
    {
        // I am getting an error in this line 'IServiceCollection does not contain a definition for Configure' 
        services.Configure<Blah>(config.GetSection("foo"));

        return services;
    }
}

What is the reason?

funatparties

You need to add https://nuget.org/packages/Microsoft.Extensions.Options package in the project where your extension method is. In the WebApi project, this package is added behind the scenes.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why don't some websites have a .html extension in their pages?

Missing extension method AddJwtBearerAuthentication() for IServiceCollection in .NET Core 2.0

I don't have Chromium, but the Software Updater keeps updating some extensions!

Why is my PodSecurityPolicy applied even if I don't have access?

Why don't I have access to anything in my GCP Project?

Why don't I have read access to files with modified ACL?

Why I don't have access to generic type class elements?

Why does Moo's builder method have access to only some of the other attributes?

Why don't I have WGL_ARB_create_context extension?

I don't have writing access to a subdirectory in /

I don't have access to class

I don't have a GetState() method for KeyboardState?

How do I give access to other users if they don't have SSH keys?

Why can I call the stream() method on objects of a class that don't have the stream()-method?

asp.net core - AddService using options iniside IServiceCollection extension

Why I have to return Some in unapply method

Can't add extension method to IConfiguration in .NET Core (but working on other classes)

Why I don't have there NotSerializableException?

Why i don't have GuildMessageReceivedEvent?

Why don't I have the 'coffee' command?

Why don't I have "undefined reference to"?

Why don't async methods in identity services in ASP.NET Core have a parameter for CancellationToken?

Why can't extensions with protocol conformances have a specific access level?

Why do std::flat_set and std::flat_map have some noexcept functions while other container adapters don't?

Don`t understand why I can`t get an access to result in another class method

ASP.NET Core WebAPI crashes because I don't have StaticFileMiddleware?

Why I don't have access to $(var.Configuration) in Product.wxs?

Debugging why I get "You don't have permission to access" in Apache 2.4

Why I don't have rw access to /run which is mounted as tmpfs in docker?