'ServiceCollection' does not contain a definition for 'AddStrawberryShakeClient'

44 Views Asked by At

Using a console application, I want to download data from a GraphQL API on my local machine.

I have added the following NuGet packages to my project in Visual Studio:

  • StrawberryShake (13.8.1)
  • StrawberryShake.CodeGeneration.CSharp (12.22.2)
  • StrawberryShake.Transport.Http (13.9.0)

I have also downloaded the schema file and stored it in a folder under the name schema.graphql.

I then added a client factory class with the following code:

using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StrawberryShake;


namespace GraphQLNamespace
{
    public class GraphQLClientFactory
    {
        public IServiceProvider CreateClient(string apiUrl)
        {
            var serviceCollection = new ServiceCollection();

            // Configure the HTTP transport
            serviceCollection.AddHttpClient("GraphQLClient", client => client.BaseAddress = new Uri(apiUrl));

            // Add StrawberryShake services
            serviceCollection.AddStrawberryShakeClient();

            return serviceCollection.BuildServiceProvider();
        }
    }
}

On the line serviceCollection.AddStrawberryShakeClient(); I get the following error:

Error CS1061 'ServiceCollection' does not contain a definition for 'AddStrawberryShakeClient' and no accessible extension method 'AddStrawberryShakeClient' accepting a first argument of type 'ServiceCollection' could be found (are you missing a using directive or an assembly reference?) MyGraphQLProject C:\Users\MY_PROFILE_NAME\source\repos\GraphQLForTOBE\GraphQLClientFactory.cs

Is there anything I am missing?

0

There are 0 best solutions below