如何使 Account 和 Manage 控制器无错误地继承自 BaseController
How to make Account and Manage controllers inherit from a BaseController without errors
我制作了一个名为 BaseController 的自定义控制器,我正在让我的所有控制器都继承自该控制器。
此控制器可用于更改 header 颜色、添加自定义文本、徽标等,我真的很想让我的管理和帐户控制器也继承它以使我的 Web 应用程序具有相同的"style" 每页。
问题是 Account 和 Manage 控制器无法从 BaseController 继承,因为它们已经有两个构造函数,一个是空的,一个带有参数 ApplicationUserManager 和 ApplicationSignInManager。
如果我尝试从 BaseController 继承,它会给我这两个构造函数的错误,说它们没有我应该从 BaseController 传递的必需形式参数。
There is no argument given that corresponds to the required formal parameter (1stParam) of BaseController.BaseController(Type1stParam, Type2ndParam, Type3rdParam, Type4thParam)
我在 Whosebug 上搜索了一段时间以找到答案,但找不到太多所以我决定提出这个问题。
这是自定义控制器。
public abstract class BaseController : Controller
{
readonly Servix2Repo.IUtente Utente;
readonly Servix2Repo.IMenu Menu;
readonly Servix2Repo.IAzienda Azienda;
readonly ServixMVCModel _context;
public BaseController(ServixMVCModel context, Servix2Repo.IUtente utenteRepo, Servix2Repo.IMenu menuRepo, Servix2Repo.IAzienda aziendaRepo)
{
_context = context;
this.Utente = utenteRepo;
this.Menu = menuRepo;
this.Azienda = aziendaRepo;
}
(Other methods)
}
这是我遇到问题的两个控制器之一。我在空构造函数和最后一个构造函数上收到错误。
public class AccountController : BaseController
{
private ApplicationSignInManager _signInManager;
private ApplicationUserManager _userManager;
public AccountController(ServixMVCModel context, Servix2Repo.IUtente utenteRepo, Servix2Repo.IMenu menuRepo, Servix2Repo.IAzienda aziendaRepo) : base(context, utenteRepo, menuRepo, aziendaRepo)
{
}
public AccountController()
{
}
public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager )
{
UserManager = userManager;
SignInManager = signInManager;
}
(Other methods)
}
感谢所有愿意帮助我的人,如果我有一些措辞错误,我很抱歉。
使用 Thangadurai's suggestion in the 修复:
In your BaseController, you do not have any default constructor that accepts no parameters. So, In all your AccountController constructors you should call the base constructor in the same way how you did it for the first constructor OR you must include one default constructor in the base class
我制作了一个名为 BaseController 的自定义控制器,我正在让我的所有控制器都继承自该控制器。
此控制器可用于更改 header 颜色、添加自定义文本、徽标等,我真的很想让我的管理和帐户控制器也继承它以使我的 Web 应用程序具有相同的"style" 每页。
问题是 Account 和 Manage 控制器无法从 BaseController 继承,因为它们已经有两个构造函数,一个是空的,一个带有参数 ApplicationUserManager 和 ApplicationSignInManager。
如果我尝试从 BaseController 继承,它会给我这两个构造函数的错误,说它们没有我应该从 BaseController 传递的必需形式参数。
There is no argument given that corresponds to the required formal parameter (1stParam) of BaseController.BaseController(Type1stParam, Type2ndParam, Type3rdParam, Type4thParam)
我在 Whosebug 上搜索了一段时间以找到答案,但找不到太多所以我决定提出这个问题。
这是自定义控制器。
public abstract class BaseController : Controller
{
readonly Servix2Repo.IUtente Utente;
readonly Servix2Repo.IMenu Menu;
readonly Servix2Repo.IAzienda Azienda;
readonly ServixMVCModel _context;
public BaseController(ServixMVCModel context, Servix2Repo.IUtente utenteRepo, Servix2Repo.IMenu menuRepo, Servix2Repo.IAzienda aziendaRepo)
{
_context = context;
this.Utente = utenteRepo;
this.Menu = menuRepo;
this.Azienda = aziendaRepo;
}
(Other methods)
}
这是我遇到问题的两个控制器之一。我在空构造函数和最后一个构造函数上收到错误。
public class AccountController : BaseController
{
private ApplicationSignInManager _signInManager;
private ApplicationUserManager _userManager;
public AccountController(ServixMVCModel context, Servix2Repo.IUtente utenteRepo, Servix2Repo.IMenu menuRepo, Servix2Repo.IAzienda aziendaRepo) : base(context, utenteRepo, menuRepo, aziendaRepo)
{
}
public AccountController()
{
}
public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager )
{
UserManager = userManager;
SignInManager = signInManager;
}
(Other methods)
}
感谢所有愿意帮助我的人,如果我有一些措辞错误,我很抱歉。
使用 Thangadurai's suggestion in the
In your BaseController, you do not have any default constructor that accepts no parameters. So, In all your AccountController constructors you should call the base constructor in the same way how you did it for the first constructor OR you must include one default constructor in the base class