【发布时间】:2021-06-04 00:08:45
【问题描述】:
这是我的解决方案
public class HomeController : Controller
{
private readonly IEventProvider _eventProvider;
public HomeController(IEventProvider eventProvider)
{
_eventProvider = eventProvider ?? throw new ArgumentNullException(nameof(eventProvider));
}
public Task<List<EventModel>> Index()
{
return this._eventProvider.GetEvents(10, 1, 0, null, null, null);
}
}
namespace WebApplication1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>();
services.AddIdentity<IdentityUserModel, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
...
services.AddScoped<ITwoFactorProvider, TwoFactorProvider>();
services.AddScoped<IEmailProvider, EmailProvider>();
services.AddScoped<IProfileProvider, ProfileProvider>();
services.AddScoped<IEventProvider, EventProvider>();
}
...
}
}
如果我尝试从控制器联系提供商,则会出现错误 我是初学者所以不要严格判断
[在此处输入图片描述][3]
请告诉我如何解决这个问题
【问题讨论】:
标签: asp.net asp.net-core .net-core asp.net-core-mvc