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

  • SEARCH
  • Home
  • 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 7927211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:11:45+00:00 2026-06-03T19:11:45+00:00

I’m creating an MVC website and also intend to create a web API for

  • 0

I’m creating an MVC website and also intend to create a web API for use both within the website and potentially by third parties.

From the MVC controllers I’ll be calling into a service layer which will contain business logic, act on domain models, perform validation, make infrastructure external service calls etc. The service layer in turn will call into repositories for any database interactions.

Now, I like the look of ServiceStack and intend on using it for the Web API – it seems more mature than the ASP.NET MVC 4 Web API. My question is, should I have the ServiceStack API call into my service layer above, similar to the MVC controllers, or should I make it the service layer, servicing both web clients and the MVC controllers?

  • 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-03T19:11:47+00:00Added an answer on June 3, 2026 at 7:11 pm

    I would do neither.

    Ideally both MVC and ServiceStack should use and share pure C# dependencies. A good example of an MVC + ServiceStack website living harmoniously together is in the SocialBootstrapApi demo project, which has been deployed on AppHarbor at: http://bootstrapapi.apphb.com

    I would register all your dependencies in your ServiceStack AppHost then register an MVC Controller factory so both your MVC Controllers and ServiceStack services get auto-wired with these dependencies.

    In your AppHost:

    void Configure(Funq.Container container) {
        container.Register<IGreeter>(c => new Greeter());
        //Set MVC to use the same Funq IOC as ServiceStack
        ControllerBuilder.Current.SetControllerFactory(
           new FunqControllerFactory(container));
    }
    

    Example of ServiceStack service using IGreeter

    public class HelloService : Service {
        public IGreeter Greeter { get; set; } //Autowired
    
        public HelloResponse Get(Hello request) {
            return new HelloResponse { 
               Result = Greeter.SayHelloTo(request.Name) };
        }
    }
    

    Example of MVC Controller using same IGreeter:

    public HelloController : ServiceStackController {
        public IGreeter Greeter { get; set; } //Autowired
    
        public void Index(string name) {
           ViewBag.GreetResult = Greeter.SayHelloTo(name);
           return View();
        }        
    }
    

    The general idea is for logic inside MVC Controllers and ServiceStack services should be concerned with the HTTP layer/integration point i.e. collecting the user input from the QueryString or FORM POST’ed variables and calling pure/testable C# logic with it then preparing the Response, in ServiceStack that would be populating the Response DTO whilst for an MVC Controller you would be populating the ViewModel.

    Calling ServiceStack services from an MVC Controller

    Although I would have Controllers + ServiceStack share functionality via a C# greet service above, you also can call a ServiceStack service from an MVC Controller like:

    public HelloController : ServiceStackController {
    
      public void Index(string name) 
      {
        using (var helloService = AppHostBase.ResolveService<HelloService>())
        {
           ViewBag.GreetResult = helloService.Get(name).Result;
           return View();
        }
      }        
    }
    

    Share Session/Caching with the ServiceStackController

    Although the MVC Controller examples inherit from the ServiceStackController, it’s not necessary but does allow you to share the same Session / Caching / Authentication + RequiredRole/RequiredPermission attributes in MVC and ServiceStack.

    See the MVC PowerPack for other benefits that ServiceStack brings to MVC.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.