Skip to content

Dependency Injection #2

@ekizito96

Description

@ekizito96

In Startup.cs this was registered as;

public void ConfigureServices(IServiceCollection services) {

services.AddMicrosoftIdentityWebAppAuthentication(Configuration)
        .EnableTokenAcquisitionToCallDownstreamApi()
        .AddInMemoryTokenCaches();

        services.AddScoped(typeof(PowerBiServiceApi));

And called in Controller as:
[Authorize]
public class HomeController : Controller
{
private PowerBiServiceApi powerBiServiceApi;

    public HomeController(PowerBiServiceApi powerBiServiceApi)
    {
        this.powerBiServiceApi = powerBiServiceApi;
    }

I get an error of "InvalidOperationException: Unable to resolve service for type 'AppOwnsData.Services.PowerBiServiceApi' while attempting to activate 'AppOwnsData.Controllers.HomeController'. "

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions