2013-04-09 63 views
2

我想實現定製服務掛鉤,這是我做的那麼遠,定製服務魚鉤使用ServiceStack

Global.asax的

public override IServiceRunner<TRequest> CreateServiceRunner<TRequest>(ActionContext actionContext) 
{   
    return new MyServiceRunner<TRequest>(this, actionContext); 
} 

MyServiceRunner.cs

public class MyServiceRunner<T> : ServiceRunner<T> { 
    public override void OnBeforeExecute(IRequestContext requestContext, TRequest request) { 
     // Called just before any Action is executed 
    } 

    public override object OnAfterExecute(IRequestContext requestContext, object response) { 
     // Called just after any Action is executed, you can modify the response returned here as well 
    } 

    public override object HandleException(IRequestContext requestContext, TRequest request, Exception ex) { 
     // Called whenever an exception is thrown in your Services Action 
    } 
} 

在global.asax中,返回語句顯示錯誤「構造函數MyServiceRunner有0個參數,但用2個參數調用」。

有人能幫助我......如果可以的話,我肯定需要使用actionContext。

回答

2

你需要一個構造函數,它應該是:

public class MyServiceRunner<T> : ServiceRunner<T> 
{ 
    public MyServiceRunner(IAppHost appHost, ActionContext actionContext) 
     : base(appHost, actionContext) {} 

    public override void OnBeforeExecute(IRequestContext requestContext, 
    TRequest request) { 
    // Called just before any Action is executed 
    } 

    public override object OnAfterExecute(IRequestContext requestContext, 
    object response) { 
     // Called just after any Action is executed, you can modify the response 
    } 

    public override object HandleException(IRequestContext requestContext, 
     TRequest request, Exception ex) { 
    // Called whenever an exception is thrown in your Services Action 
    } 
} 
+0

再次感謝大家。由於這是我的第一個ServiceStack項目,所以您的建議非常有價值。 – quickLearner 2013-04-10 14:43:14

+0

謝謝,這很有幫助。由於文檔(https://github.com/ServiceStack/ServiceStack/wiki/New-Api#custom-hooks)未能包含構造函數,因此我在圈子中轉了一圈。 – ctrlplusb 2013-12-05 16:58:17