title: Is there are a way to do Dependency injection inside ObjectGraphType
body: <p>I am doing a simple tutorial for GraphQL.
  Many old examples are confusing or don't work with .NET 5 and newest Nuget package. I am building GraphQL application and there is a tutorial where this code works :</p>
  <pre><code>public DragonType(DragonExpertOpinionRepository rep)
  {
      Field&lt;ListGraphType&lt;DragonOpinionType&gt;&gt;(&quot;opinions&quot;,
          resolve: context =&gt; rep.GetForDragonId(context.Source.Id));
      
      Field(t =&gt; t.Id);
  </code></pre>
  <p>The problem is this constructor. I have no idea how I can resolve this. I tried some magic with &quot;IServiceProvider&quot; but this also isn't resolved. How GrapQL can know how to inject &quot;DragonExpertOpinionRepository&quot;?</p>
  <p>This is my code in Startup.cs</p>
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddDragonPersitence(Configuration);
  
  
      services.AddScoped&lt;DragonType&gt;(sp =&gt;
      {
          return new DragonType(sp.GetRequiredService&lt;DragonExpertOpinionRepository&gt;());
      });
  
      services.AddScoped&lt;DragonSchema&gt;();
  
      services.AddGraphQL(o =&gt; { })
       .AddGraphTypes(ServiceLifetime.Scoped)
       .AddNewtonsoftJson();
  
      // If using Kestrel:
      services.Configure&lt;KestrelServerOptions&gt;(options =&gt;
      {
          options.AllowSynchronousIO = true;
      });
  
      // If using IIS:
      services.Configure&lt;IISServerOptions&gt;(options =&gt;
      {
          options.AllowSynchronousIO = true;
      });
  }
  </code></pre>
  <p>DragonSchema :</p>
  <pre><code>public class DragonSchema : Schema
  {
      private readonly DragonShopDbContext _dbContext;
  
      public DragonSchema(DragonShopDbContext dbContext) : base()
      {
          _dbContext = dbContext;
  
          Query = new DragonQuery
             (new DragonRepository(_dbContext));
      }
  }
  </code></pre>
  <p>And DragonQuery :</p>
  <pre><code>public class DragonQuery : ObjectGraphType
  {
      public DragonQuery(DragonRepository productRepository)
      {  
          Field&lt;ListGraphType&lt;DragonType&gt;&gt;(
              &quot;dragons&quot;,
              resolve: context =&gt; productRepository.GetAll()
  
          );
      }
  }
  </code></pre>
  <p>I am accepting simple answer : &quot;WTF are doing&quot;. Tutorial that is doing this is wrong.
  You can Injecting stuff only in GraphQL Schema.</p>