title: Can ServiceStack services contain multiple methods?
body: <p>Environment is Visual Studio 2012, ServiceStack, ASP.NET Web Application Project (followed <a href="https://github.com/ServiceStack/ServiceStack/wiki/Create-your-first-webservice" rel="nofollow noreferrer">https://github.com/ServiceStack/ServiceStack/wiki/Create-your-first-webservice</a>)</p>
  
  <p>Looking through some of the classes in ServiceStack.Examples, I noticed that most of the services contain only one method. Either some override on <code>Execute()</code> or, if a REST service, some override of <code>OnPost/Get/Put/Delete()</code>. </p>
  
  <p>How should I approach making a full API set, if I have tens of functions I need implemented <code>RegisterUser()</code>, <code>RemoveUser()</code>, <code>AddFriend()</code>, <code>RemoveFriend()</code> ... One service per method? </p>
  
  <pre><code>public RegisterUserService : IService&lt;User&gt; { public object Execute(User&gt; dto) { ... } }
  public RemoveUserService : IService&lt;User&gt; { public object Execute(User&gt; dto) { ... } }
  public AddFriendService : IService&lt;Friend&gt; { public object Execute(Friend dto) { ... } }
  public RemoveFriendService: IService&lt;RequestDTO4&gt; { public object Execute(Friend dto) { ... } }
  </code></pre>
  
  <p>I'm pretty lost on how to begin implementing a full API set. I've read the <a href="https://github.com/ServiceStack/ServiceStack/wiki/Create-your-first-webservice" rel="nofollow noreferrer">first</a> and <a href="https://github.com/ServiceStack/ServiceStack/wiki/Your-first-webservice-explained" rel="nofollow noreferrer">second</a> wiki page on 'Creating your first webservice', which I've copied to make 1 service method. But now I want to make 10 or 40 service methods and I'm not sure how to do that. </p>
  
  <p>I noticed that implementing from <code>IRestService&lt;T&gt;</code> allows you up to 4 methods instead of the one <code>Execute()</code> method, simply because each method corresponds to a different HTTP verb. So is there something like that I could write? Basically something like:</p>
  
  <pre><code>public MyService : IService/IRestService/ServiceBase?&lt;User&gt;
  {
       public object AddUser(User user) { }
       public object RemoveUser(User user) { }
       public object ModifyUser(User user) { }
  }
  </code></pre>
  
  <p>Just looking for something that doesn't necessarily have to contain all methods in one service class, but as many as reasonably possible ... do I really have to create 1 service for each service method? </p>
  
  <p>Note on pursuing a strictly RESTful architecture: I only read up a little on REST, but it seems like I'd have to strictly follow rules like: treat everything as a resource even if you have to re-design your models, no verbs in the URL names (/Friends, not /GetFriends because REST gives you OnGet(), OnPost(), OnPut(), and OnDelete() ... basically I'm interested in the easiest, quickest, and most painless way of implementing a a few dozen service methods. It's a personal project, so the requirements won't vary too much.</p>
  
  <p>Thanks in advance for guiding me through this first step.</p>
  
  <p>EDIT: Just saw this related question: <a href="https://stackoverflow.com/questions/10060919/how-to-send-commands-using-servicestack?rq=1">How to send commands using ServiceStack?</a></p>
  
  <p>Mythz said there's no "ServiceStack way" to design. The guy's question is pretty much like mine. I'm wondering how to stack a lot of service methods in a service.</p>
  
  <p>EDIT 2: Just saw <a href="https://stackoverflow.com/questions/8007232/need-help-on-servicestack-implementation">Need help on servicestack implementation</a>, and <a href="https://stackoverflow.com/questions/8415972/separate-or-combined-servicestack-services?rq=1">Separate or combined ServiceStack services?</a>.</p>
  
  <p>I just tested the code below successfully with working routes:</p>
  
  <pre><code>[Route("/registerUser/setEmail/{Email}")]
  [Route("/registerUser/setPassword/{Password}")]
  [Route("/registerUser/setPhoneNumber/{PhoneNumber}")]
  [Route("/lalal2395823")]
  [Route("/test3234/test23423511")]
  public class RegisterUser
  {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string Nickname { get; set; }
      public string PhoneNumber { get; set; }
      public string Email { get; set; }
      public string Password { get; set; }
  }
  </code></pre>
  
  <p>But <strong>what I'd like is for each <code>[Route("path")]</code> to go to a <em>different</em> method</strong>, instead of having them all parsed in <code>Execute()</code> and having to parse which string isn't null or empty.</p>
  
  <hr>
  
  <h2>My Solution</h2>
  
  <p>I decided to take Rickard's advice and make a proper REST API, because it seems simpler and cleaner in the end.</p>
  
  <p>This is now my class using <a href="https://github.com/ServiceStack/ServiceStack/wiki/New-API" rel="nofollow noreferrer">the new ServiceStack API (new as of 9/24/12)</a>:</p>
  
  <pre><code>using UserModel = Project.Model.Entities.User;
  
  [Route("/User", "POST")]
  [Route("/User/{FirstName}", "POST")]
  [Route("/User/{FirstName}/{LastName}", "POST")]
  [Route("/User/{FirstName}/{LastName}/{Nickname}", "POST")]
  [Route("/User/{FirstName}/{LastName}/{Nickname}/{PhoneNumber}", "POST")]
  [Route("/User/{FirstName}/{LastName}/{Nickname}/{PhoneNumber}/{Email}", "POST")]
  public class CreateUser : IReturn&lt;UserModel&gt;
  {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string Nickname { get; set; }
      public string PhoneNumber { get; set; }
      public string Email { get; set; }
      public string Password { get; set; }
  }
  
  public class CreateUserService : Service
  {
     public object Post(CreateUser request)
      {
          try
          {
              using (var session = FluentNHibernateHelper.OpenSession())
              {
                  using (var transaction = session.BeginTransaction())
                  {
                      var user = new UserModel()
                      {
                          FirstName = request.FirstName,
                          LastName = request.LastName,
                          Nickname = request.Nickname,
                          PhoneNumber = request.PhoneNumber,
                          Email = request.Email,
                          Password = request.Password,
                      };
                      session.SaveOrUpdate(user);
                      transaction.Commit();
  
                      return user;
                  }
              }
          }
          catch
          {
              throw;
          }
      }
  }
  </code></pre>