我试图让一个基本服务层在我的应用程序中工作,但我遇到了麻烦。
界面:
public interface IEmailer
{
string ServiceTest();
}
服务:
public class SimpleMailer : IEmailer
{
public string ServiceTest()
{
var ServiceVar = "This is your service working";
return ServiceVar;
}
}
控制器:
public class EmailSendController : Controller
{
private IEmailer _service;
public EmailSendController()
{
_service = new SimpleMailer();
}
public EmailSendController(IEmailer service)
{
_service = service;
}
[HttpPost]
public ActionResult Edit()
{
_service.ServiceTest();
return View();
}
}
}
我收到一个_service.ServiceTest();
空错误。我做错了什么阻止它返回ServiceVar
?