Phương pháp lọc WebApi của tôi OnActionExecuted
đang được gọi hai lần. lọc của tôi (tôi làm cho nó càng đơn giản càng tốt):Bộ lọc tác vụ WebApi được gọi hai lần
public class NHibernateActionFilter : ActionFilterAttribute
{
// [Inject]
// public ISessionFactoryProvider sessionFactoryProvider { get; set; }
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
var a = 5;
var b = a;
//new BaseSessionProvider(sessionFactoryProvider).EndContextSession();
}
}
thiết lập của tôi:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
//http://stackoverflow.com/questions/9521040/how-to-add-global-asp-net-web-api-filters
FilterConfig.RegisterWebApiFilters(GlobalConfiguration.Configuration.Filters);
}
public class FilterConfig
{
public static void RegisterWebApiFilters(System.Web.Http.Filters.HttpFilterCollection filters)
{
filters.Add(new NHibernateActionFilter());
}
}
Trong debugger tôi bắt OnActionExecuted
hai lần với cùng actionExecutedContext
. Tại sao?
UPD
Controller
public class BankSmsController : ApiController
{
[AcceptVerbs(HttpVerbs.Get)]
public int GetTest()
{
return 1;
}
}
Tôi nhận thấy một thuộc tính 'Tiêm' đã nhận xét - có thể có cấu hình NInject nào cũng thiết lập bộ lọc để nó được thêm hai lần không? Bạn đã xác nhận rằng chỉ có một thể hiện của bộ lọc trong bộ sưu tập bộ lọc toàn cục sau khi tất cả mã khởi động đã kết thúc chạy? – levelnis
Không có ninject nào cả. Tôi loại bỏ 'kernel.BindFilter (FilterScope.Global, 1);' –
bạn có thể hiển thị bộ điều khiển không? –