无法从根提供程序解析作用域服务Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.IViewBufferScope [英] Cannot resolve scoped service Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.IViewBufferScope from root provider
问题描述
我正在尝试在我的ASP.NET Core 2.0 Web应用程序中使用此示例 RazorViewEngineEmailTemplates 从View创建HTML电子邮件正文.但是当我运行它并且我的控制器收到ajax请求时,我得到了这个错误:
I'm trying to use in my ASP.NET Core 2.0 web app this sample RazorViewEngineEmailTemplates to create an html email body from View. But when I run it and my controller gets an ajax request, I get this error:
无法从根提供程序解析作用域服务Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.IViewBufferScope
Cannot resolve scoped service Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.IViewBufferScope from root provider
它可能来自解析 RazorViewToStringRenderer类中的依赖项,但我不知道如何解决.
It's probably coming from resolving dependencies in the RazorViewToStringRenderer class but I have no idea how to fix this.
推荐答案
好的,问题是我使用了Singleton服务(EmailerService)中的渲染器.我将其注册更改为Scoped,并且现在都可以使用:
ok, the problem was I used renderer from a Singleton service (EmailerService). I changed its registration to Scoped and it all works now:
services.AddScoped<IEmailer, EmailerService>();
这篇关于无法从根提供程序解析作用域服务Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.IViewBufferScope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!