title: GraphQL.net injecting service into a graph type object
body: <p>I'm trying to utilize dependency injection in GraphQL.net to resolve fields on a graph type, but I keep getting the following error:</p>
  <pre><code>System.Exception: Failed to call Activator.CreateInstance. Type: graphql_di.Models.MyObjectGraphType
   ---&gt; System.MissingMethodException: Cannot dynamically create an instance of type 'graphql_di.Models.MyObjectGraphType'. Reason: No parameterless constructor defined.
  </code></pre>
  <p>I've set up a clean .NET 6 web API for testing it, like so:</p>
  <p><strong>MyObject.cs</strong></p>
  <pre><code>public class MyObject
  {
      public MyObject(string someProperty)
      {
          SomeProperty = someProperty;
      }
  
      public string SomeProperty { get; }
  }
  </code></pre>
  <p><strong>MyObjectGraphType</strong></p>
  <pre><code>public class MyObjectGraphType : ObjectGraphType&lt;MyObject&gt;
  {
      public MyObjectGraphType(IMyService myService)
      {
          Field&lt;StringGraphType&gt;(name: &quot;someProperty&quot;, resolve: x =&gt; x.Source?.SomeProperty ?? string.Empty);
          Field&lt;StringGraphType&gt;(name: &quot;name&quot;, resolve: x =&gt; myService.GetMyName());
      }
  }
  </code></pre>
  <p><strong>RootQuery.cs</strong></p>
  <pre><code>public class RootQuery : ObjectGraphType
  {
      public RootQuery()
      {
          Field&lt;MyObjectGraphType&gt;(
              name: &quot;myquery&quot;,
              resolve: _ =&gt;
              {
                  MyObject myObject = new(&quot;some pre-populated property&quot;);
                  return myObject;
              }
          );
      }
  }
  </code></pre>
  <p><strong>MySchema.cs</strong></p>
  <pre><code>public class MySchema : Schema
  {
      public MySchema(IServiceProvider serviceProvider) : base(serviceProvider)
      {
          Query = serviceProvider.GetRequiredService&lt;RootQuery&gt;();
      }
  }
  </code></pre>
  <p><strong>Program.cs</strong></p>
  <pre><code>var builder = WebApplication.CreateBuilder(args);
  
  builder.Services
      .AddMvc()
      .AddMvcOptions(x =&gt; x.EnableEndpointRouting = false);
  
  builder.Services.AddSingleton&lt;IMyService, MyService&gt;();
  
  builder.Services.AddGraphQL()
      .AddSchema&lt;MySchema&gt;()
      .AddDataLoader()
      .AddGraphTypes();
  
  builder.Services.AddEndpointsApiExplorer();
  builder.Services.AddSwaggerGen();
  
  var app = builder.Build();
  app.UseMvc();
  app.UseSwagger();
  app.UseSwaggerUI();
  
  app.Run();
  </code></pre>
  <p>Dependency injection is working in the sense, that I can inject <code>IMyService</code> into <code>RootQuery</code>s constrcutor, but it's not working on <code>MyObjectGraphType</code></p>
  <p>Does anyone know what I am missing here?</p>
  <p>Any help/hint is greatly appreciated :-)</p>