看起来很疯狂,这样的事情让我很头疼.但这里是:
对于非控制器类,如何为内核使用内置依赖注入?请提供包含实例化的示例.
谢谢.
只需将课程作为服务即可。
在startup.cs中
services.AddScoped();
然后在控制器中,与对其他服务的操作相同:
private readonly AccountBusinessLayer _ABL;
与其他服务一样,包含在构造函数中:
public AccountController( UserManageruserManager, SignInManager signInManager,IOptions identityCookieOptions, IEmailSender emailSender, ISmsSender smsSender, ILoggerFactory loggerFactory, RoleManager roleManager, AccountBusinessLayer ABL ) { _userManager = userManager; _signInManager = signInManager; _externalCookieScheme = identityCookieOptions.Value.ExternalCookieAuthenticationScheme; _emailSender = emailSender; _smsSender = smsSender; _logger = loggerFactory.CreateLogger (); _roleManager = roleManager; _ABL = ABL; }