1

Is it possible to do something like this?

Query.cs

class Query<T> : ObjectType<MyQuery<T>> where T : class
{
    protected override void configure(IObjectTypeDescriptor<MyQuery<T>> descriptor)
    {
        descriptor
             .Field(f => f.GetItems)
             .Description("Return List");
    }
}

public partial class MyQuery<T> where T : class
{
    private readonly IGenericRepositorty _repo

    public MyQuery(IGenericRepositorty repo)
    {
        _repo = repo;
    }

    public IEnumerable<T> GetItems()
    {
        return _repo.GetAll();   // GetAll in generic repo
    }
}

Now if I am adding my service in Startup.cs as

services.AddQueryType<MyQuery<Entity>>();

It works.

But I want to add it as

services.AddQueryType<MyQuery<>>(); or kind of services.AddQueryType(typeOf(MyQuery<>));

The way we inject generic repo like this

services.AddScoped(typef(IGenericRepository<>),typeofGenericRepository<>)

So, here at run time it creates an instance.

The same way for query at run time I am trying whether it will be possible to create instance

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

0 Answers0