1
我开发在asp.net应用程序中,我实现了Ninject拦截在我绑定/注册像Ninject拦截器调用两次beforeinvoke和afterinvoke方法
kernel.Bind<IPracticeManagement>().To<PracticeManagementClient>().InRequestScope().Intercept().With<TimingInterceptor>();
服务。当我打电话了此服务的方法
public class HomeController : Controller
{
private readonly IPracticeManagement _practiceManagement;
public HomeController(IPracticeManagement practiceManagement)
{
this._practiceManagement = practiceManagement;
}
public ActionResult Index()
{
var specialities = this._practiceManagement.GetSpecialty();
this.ViewBag.Specialities = specialities;
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
}
BeforeInvoke在TimeInterceptor中调用两次的方法。为什么?
你是否在'GetSpecialty'中放置了一个断点?它被调用了一次还是两次?另外你的'TimingInterceptor'实现是怎么样的? – nemesv
GetSpecialty正在调用一次。 – Billz
然后,你应该在BeforeIncoke中放置一个断点,并检查'调用'可能是第二次请求'GetSpecialty'和一个不同的方法... – nemesv