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