Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9251077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:36:23+00:00 2026-06-18T10:36:23+00:00

I am developing a (hopefully) RESTful API using ServiceStack. I noticed that most of

  • 0

I am developing a (hopefully) RESTful API using ServiceStack.

I noticed that most of my services look the same, for example, a GET method will look something like this:

        try
        {
            Validate();
            GetData(); 
            return Response();
        }
        catch (Exception)
        {
            //TODO: Log the exception
            throw; //rethrow
        }

lets say I got 20 resources, 20 request DTOs, so I got about 20 services of the same template more or less…

I tried to make a generic or abstract Service so I can create inheriting services which just implement the relevant behavior but I got stuck because the request DTOs weren’t as needed for serialization.

Is there any way to do it?

EDIT:

an Example for what I’m trying to do:

public abstract class MyService<TResponse,TRequest> : Service
{
    protected abstract TResponse InnerGet();
    protected abstract void InnerDelete();
    public TResponse Get(TRequest request)
    {
        //General Code Here.
        TResponse response = InnerGet();
        //General Code Here.
        return response;
    }

    public void Delete(TRequest request)
    {
        //General Code Here.
        InnerDelete();
        //General Code Here.
    }
}

public class AccountService : MyService<Accounts, Account>
{

    protected override Accounts InnerGet()
    {
        throw new NotImplementedException();//Get the data from BL
    }

    protected override void InnerDelete()
    {
        throw new NotImplementedException();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:36:25+00:00Added an answer on June 18, 2026 at 10:36 am

    To do this in the New API we’ve introduced the concept of a IServiceRunner that decouples the execution of your service from the implementation of it.

    To add your own Service Hooks you just need to override the default Service Runner in your AppHost from its default implementation:

    public virtual IServiceRunner<TRequest> CreateServiceRunner<TRequest>(ActionContext actionContext)
    {           
        return new ServiceRunner<TRequest>(this, actionContext); //Cached per Service Action
    }
    

    With your own:

    public override IServiceRunner<TRequest> CreateServiceRunner<TRequest>(ActionContext actionContext)
    {           
        return new MyServiceRunner<TRequest>(this, actionContext); //Cached per Service Action
    }
    

    Where MyServiceRunner is just a custom class implementing the custom hooks you’re interested in, e.g:

    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
        }
    }
    

    Also for more fine-grained Error Handling options check out the Error Handling wiki page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For developing an devices monitor system, I am using a InetAdress isReachable method to
I am currently developing a system that will, hopefully, be used to compare the
I'm developing a very simple but (hopefully) solid framework that just fits my needs.
Im in the middle of developing a product that i will hopefully be attempting
Currently, I am developing a product that does fairly intensive calculations using MS SQL
I'm developing a social media network, so the user base will hopefully be that
I'm developing directly on the mobile device, and I have some questions you hopefully
Iam developing one application.In that iam placing the radio buttons(uiimageview) on table view and
While developing an application using gwt in ecliplse crashed. Now the server is running
Looking into developing new startup with potential of hopefully having high volume. Initial idea

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.