我正在为ASP .NET Core 2.1构建一个中间件,该中间件将从上下文中提取一些信息并将其注入IService。 当前,有几种服务(配置文件,用户),都实现了IService接口。
但是,当发布到Profile服务时,另一个Users服务正在注入到中间件中。 但是,在Profile控制器中,注入了正确的服务,因此这似乎不是DI问题。
public async Task Invoke(HttpContext context, IService theService)
{
UserInfo serInfo = await GetUserInfoAsync(context).ConfigureAwait(false);
theService.UserInfo = userInfo;
}
根据Microsoft this should be possible。
有什么想法为什么不起作用?