GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.servicestack.net — ASP.NET MVC Integration ASP.NET MVC IntegrationTIP These docs only apply to ASP .NET Framework MVC projects, for .NET Core see MVC Project Templates Add ServiceStack to an existing MVC ProjectYou can easily add ServiceStack to any ASP.NET MVC project by getting it from NuGet with:
This install ServiceStack with additional (and optional) integration support for MVC letting you use ServiceStack's IOC to initialize MVC controllers or create MVC Controllers with built-in access to ServiceStack's components. Enabling ServiceStack in Web.ConfigTypically when hosting ServiceStack with MVC you'd want to host it at the
INFO See Run Side-by-Side with another web framework for other web.config examples of hosting ServiceStack, e.g with IIS6/Mono Add your ServiceStack AppHostThe smallest ServiceStack AppHost for MVC would look something like:
Inferring ServiceStack's HandlerFactoryPath (/api)Whilst ServiceStack automatically tries to infer the handler path based on the
Initializing ServiceStackHosting in ASP.NET MVC is very similar to hosting in any ASP.NET framework, i.e. The ServiceStack AppHost still needs to be initialized on start up in your
You MUST also register ServiceStacks
Place them before the current entries the method. Removing Web APIFor MVC applications that include WebApi, you would need to unregister it by commenting out this line:
Optional ConfigurationSharing dependencies with MVC ControllersTo register all your dependencies in your ServiceStack AppHost, register an MVC Controller factory so both your MVC Controllers and ServiceStack services get auto-wired with these dependencies in your
Calling ServiceStack Services from MVC ControllersUsing the Service GatewayThe preferred method for calling ServiceStack Services is via the loosely-coupled Service Gateway:
Calling Services DirectlyAlternatively just like in ServiceStack, you can retrieve an autowired Service and execute it directly using
For any other external methods or MVC Controllers that don't inherit
Another cleaner way to share functionality between MVC and ServiceStack is to get them both injected with a shared dependency. See the IGreeter example on StackOverflow. Adding Mini ProfilerTo enable the Mini Profiler add the following lines in to MvcApplication in Global.asax.cs:
For more info on the MiniProfiler see the Built in profiling docs. Accessing ServiceStack from MVCOnce you have MVC + ServiceStack up and running checkout ServiceStack Integration docs to explore different ways of accessing ServiceStack from MVC. On This Page
|
| You are visitor 01402860 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |