I'm exploring GraphQL at the moment. In one of my ObjectGraphTypes
I want to inject a service implementation which queries EF about some addition data.
public class RoomType : ObjectGraphType<Room>
{
public RoomType(IUserRepository userRepository)
{
Field(x => x.Id).Description("Identifier for a room");
Field(x => x.Name).Description("Name of the room");
Field<ListGraphType<UserType>, IEnumerable<User>>().Name("Users").Resolve(ctx =>
{
var roomId = ctx.Source.Id;
return userRepository.GetUsersInRoom(roomId);
});
}
}
Where both RoomType and IUserRepository has been registed within in Autofac container. However, during execution the RoomType cannot be resolved as it's missing a parameterless constructor, which makes me think that its been construction via reflection and not via the container. Any suggestions on how to proceed?
Thanks!