我是 ASP.NET 和 C# 的新手。
当我向没有构造函数的控制器方法发出 GET 请求时,我得到 200 响应。例如,
没有构造函数的控制器
[Route("api/[controller]")]
public class ApiController : Controller
{
protected static BusinessLogic BusinessLogic;
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
但是当我实例化构造函数时,我得到了 500 响应。我错过了什么?
控制器
[Route("api/[controller]")]
public class ApiController : Controller
{
protected static BusinessLogic BusinessLogic;
public ApiController(BusinessLogic businessLogic)
{
BusinessLogic = businessLogic;
}
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
商业逻辑
public class BusinessLogic
{
private readonly Encryption _encryption;
private readonly string UserID;
private readonly string Password;
public BusinessLogic(string Key, string Url, string UserId, string Password)
{
_encryption = new Encryption(Key);
_UserID = UserId;
_Password = Password;
}
MM们
胡说叔叔
相关分类