Skip to content
mythz edited this page Feb 27, 2012 · 23 revisions

As of v3.55 ServiceStack introduces a new Plugin API that all of ServiceStack add-ons now implement:

Plugin API

public interface IPlugin
{
    void Register(IAppHost appHost);
}

All built-in Plugins are Registered and available via base.Plugins before your Configure() script is run so you have a chance to modify the behaviour or remove un-used plugins which is exactly what the short-hand:

SetConfig(new EndpointHostConfig { 
    EnableFeatures = Features.All.Remove(Features.Csv)
});

Which under the covers just does:

if ((Feature.Csv & config.EnableFeatures) != Feature.Csv)
	Plugins.RemoveAll(x => x is CsvFormat);

Which you now also have an opportunity to also do in your AppHost Configure() start-up script yourself - if you want to remove or customize any pre-loaded plugins.

You can easily use LINQ to fetch any specific plugin:

var htmlFormat = (HtmlFormat)base.Plugins.First(x => x is HtmlFormat);

List of Plugins

A list of all of the plugins available on ServiceStack and how to add them:

Already registered by default

These plugins below are already added by default, you can remove or customize them using the methods described above.

Providing ServiceStack's CSV Format.

Plugins.Add(new CsvFormat()); 

Note: By default the CSV Format tries serialize the Response object directly into CSV which is only ideal if your responses return List<Poco>. If however you mark your Response DTO with the [DataContract]/[DataMember] attributes the CSV Format instead will only serialize the first List<Poco> it finds on your Response DTO e.g. if you had a List<Poco> Results property it will only serialize this list in the tabular CSV Format which is typically the behaviour you want.

Providing ServiceStack's Html Format.

Plugins.Add(new HtmlFormat()); 

This provides ServiceStack's Razor Markdown Format and also enables ServiceStack to serve static .md or .markdown files in either plain text, rendered as HTML (partial), or rendered in HTML inside a static default.shtml HTML template.

Plugins.Add(new MarkdownFormat()); 

The entire www.servicestack.net/docs website is rendered using static Markdown. More information of Razor Markdown features can be found in:

Available Plugins

The rest of ServiceStack's plugins are not enabled by default by can easily be added on adhoc basis, as and when needed.

Validation

Enable the validation feature if you want to ensure all of ServiceStack's Fluent validators for Request DTOs IValidator<TRequestDto> are automatically validated on every request.

Plugins.Add(new ValidationFeature());

More information on ServiceStack's built-in Fluent Validation support is described on the Validation page.

Authentication

The Authentication Feature enables the Authentication and Authorization support in ServiceStack. It makes available the AuthService at the default route at /auth/{provider}, registers AssignRoles and UnAssignRoles services (at /assignroles and /unassignroles default routes) and auto-enables Session support if it's not added already.

An example AuthFeature registration (taken from the SocialBootstrapApi project):

Plugins.Add(new AuthFeature(
	() => new CustomUserSession(), //Use your own typed Custom UserSession type
	new IAuthProvider[] {
	    new CredentialsAuthProvider(),         //HTML Form post of UserName/Password credentials
	    new TwitterAuthProvider(appSettings),  //Sign-in with Twitter
	    new FacebookAuthProvider(appSettings), //Sign-in with Facebook
	    new BasicAuthProvider(),               //Sign-in with Basic Auth
	}));

This registers and provides your ServiceStack host a myriad of different Authentication options as described above.

Session support

If you're not using the AuthFeature above and you still want Session support you need to enable it explicitly with:

Plugins.Add(new SessionFeature());

This will add a Request Filter to instruct any HTTP client calling a ServiceStack web service to create a Temporary (ss-id) and Permanent (ss-pid) cookie if not already done so.

Registration

Related to Authentication is Registration which enables the Registration Service at the default route /register which lets new Users to be registered and validated with the Credentials and Basic AuthProviders.

Plugins.Add(new RegistrationFeature());

See the SocialBootstrapApi project for a working example of Registration and Authentication.

ProtoBuf format

Best way to enable ProtoBuf support is to install the ServiceStack.Plugins.ProtoBuf NuGet package which auto registers the plugin for you. However if you don't want to use NuGet you can add a reference to the ServiceStack.Plugins.ProtoBuf.dll and register the plugin with:

Plugins.Add(new ProtoBufFormat());


  1. Getting Started
    1. Create your first webservice
    2. Your first webservice explained
    3. ServiceStack's new API Design
    4. Designing a REST-ful service with ServiceStack
    5. Example Projects Overview
  2. Reference
    1. Order of Operations
    2. The IoC container
    3. Metadata page
    4. Rest, SOAP & default endpoints
    5. SOAP support
    6. Routing
    7. Service return types
    8. Customize HTTP Responses
    9. Plugins
    10. Validation
    11. Error Handling
    12. Security
    13. Debugging
  3. Clients
    1. Overview
    2. C# client
    3. Silverlight client
    4. JavaScript client
    5. Dart Client
    6. MQ Clients
  4. Formats
    1. Overview
    2. JSON/JSV and XML
    3. ServiceStack's new HTML5 Report Format
    4. ServiceStack's new CSV Format
    5. MessagePack Format
    6. ProtoBuf Format
  5. View Engines 4. Razor & Markdown Razor
    1. Markdown Razor
  6. Hosts
    1. IIS
    2. Self-hosting
    3. Messaging
    4. Mono
  7. Security
    1. Authentication/authorization
    2. Sessions
    3. Restricting Services
  8. Advanced
    1. Configuration options
    2. Access HTTP specific features in services
    3. Logging
    4. Serialization/deserialization
    5. Request/response filters
    6. Filter attributes
    7. Concurrency Model
    8. Built-in caching options
    9. Built-in profiling
    10. Form Hijacking Prevention
    11. Auto-Mapping
    12. HTTP Utils
    13. Virtual File System
    14. Config API
    15. Physical Project Structure
    16. Modularizing Services
    17. MVC Integration
  9. Plugins 3. Request logger 4. Swagger API
  10. Tests
    1. Testing
    2. HowTo write unit/integration tests
  11. Other Languages
    1. FSharp
    2. VB.NET
  12. Use Cases
    1. Single Page Apps
    2. Azure
    3. Logging
    4. Bundling and Minification
    5. NHibernate
  13. Performance
    1. Real world performance
  14. How To
    1. Sending stream to ServiceStack
    2. Setting UserAgent in ServiceStack JsonServiceClient
    3. ServiceStack adding to allowed file extensions
    4. Default web service page how to
  15. Future
    1. Roadmap

Clone this wiki locally