[英]Getting users from UserManager using HotChocolate
How to get list of users from UserManager
from Microsoft.AspNetCore.Identity
using [ScopedService]
如何使用
[ScopedService]
从Microsoft.AspNetCore.Identity
的UserManager
获取用户列表
Below is what I already tried:以下是我已经尝试过的:
using System.Linq;
using hostapp.Data;
using hostapp.Models;
using HotChocolate;
using HotChocolate.Data;
using Microsoft.AspNetCore.Identity;
namespace hostapp.GraphQL
{
public class Query
{
// 1.
[UseDbContext(typeof(DataContext))]
public IQueryable<AppUser> Users([ScopedService] UserManager<AppUser> userManager)
{
return (IQueryable<AppUser>)userManager.Users;
}
// 2.
[UseDbContext(typeof(DataContext))]
public async Task<List<AppUser>> Users([ScopedService] UserManager<AppUser> userManager)
{
return await userManager.Users.ToListAsync();
}
}
}
Input:输入:
query {
users {
emailConfirmed
}
}
Output: Output:
{
"errors": [
{
"message": "Unexpected Execution Error",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"users"
]
}
],
"data": {
"users": null
}
}
You do not need to use [ScopedService]
but rather [Service]
You really only even need to use [ScopedService]
in case of a DBContext
in combination with UseDbContext
.您不需要使用
[ScopedService]
而是[Service]
在 DBContext 与DBContext
结合使用的情况下,您实际上甚至只需要使用[ScopedService]
UseDbContext
We will fix this confusion in the next version我们将在下一个版本中修复这种混淆
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.