GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Plugins Plugins
Demis Bellot edited this page
This page has moved to docs.servicestack.net/pluginsServiceStack Plugin API provides a declarative way to enable modular functionality in ServiceStack: public interface IPlugin { void Register(IAppHost appHost); } If your plugin also implements public interface IPreInitPlugin { void Configure(IAppHost appHost); } If your plugin implements public interface IPostInitPlugin { void AfterPluginsLoaded(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 HostConfig { EnableFeatures = Feature.All.Remove(Feature.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 = base.Plugins.First(x => x is HtmlFormat) as HtmlFormat; Which is also what the var htmlFormat = base.GetPlugin<HtmlFormat>(); A list of all of the plugins available on ServiceStack and how to add them: These plugins below are already added by default, you can remove or customize them using the methods described above. Provides ServiceStack's auto-generated metadata pages. var feature = Plugins.FirstOrDefault(x => x is MetadataFeature); Plugins.RemoveAll(x => x is MetadataFeature); Provides ServiceStack's pre-defined routes used in the built-in C# Service Clients. var feature = Plugins.FirstOrDefault(x => x is PredefinedRoutesFeature); Plugins.RemoveAll(x => x is PredefinedRoutesFeature); Provides ServiceStack's Request Info feature useful for debugging requests. Just add ?debug=requestinfo in your var feature = Plugins.FirstOrDefault(x => x is RequestInfoFeature); Plugins.RemoveAll(x => x is RequestInfoFeature); Providing ServiceStack's CSV Format. var feature = Plugins.FirstOrDefault(x => x is CsvFormat); Plugins.RemoveAll(x => x is CsvFormat); Note: By default the CSV Format tries serialize the Response object directly into CSV which is only ideal if your responses return Providing ServiceStack's Html Format. var feature = Plugins.FirstOrDefault(x => x is HtmlFormat); Plugins.RemoveAll(x => x is 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 _Layout.shtml HTML template. var feature = Plugins.FirstOrDefault(x => x is MarkdownFormat); Plugins.RemoveAll(x => x is MarkdownFormat); The entire docs.servicestack.net website is rendered using static Markdown. More information of Razor Markdown features can be found in: The rest of ServiceStack's plugins are not enabled by default by can easily be added on adhoc basis, as and when needed. AutoQuery enables instant querying support on RDBMS tables behind clean self-describing APIs by enhancing the ideal API the developer would naturally write and completing their implementation for them! This is essentially the philosophy behind AutoQuery which utilizes conventions to automate creation of intent-based self-descriptive APIs that are able to specify configurable conventions and leverage extensibility options to maximize the utility of AutoQuery services. Plugins.Add(new AutoQueryFeature { MaxLimit = 100 });
Server Events enables server push notifications to create real-time responsive web apps with its support for Server Sent Events. It offers a number of different API's for sending notifications to select users at different levels of granularity, letting you interact and modify live-running web apps. Plugins.Add(new ServerEventsFeature()); The Postman Rest Client is a very popular and easy to use HTTP Request composer that makes it easy to call web services, similar to Fiddler's Composer. It also provides as an alternative for auto-generating API documentation to ServiceStack's Swagger support that makes it easier to call existing services but does require users to install the Postman Rest Client. Plugins.Add(new PostmanFeature()); Plugins.Add(new CorsFeature()); Swagger support an optional add-on available in the ServiceStack.Api.Swagger NuGet package. After installing the NuGet package enable the Swagger with: Plugins.Add(new SwaggerFeature()); Now you can enjoy your shiny new Swagger UI at: You can further document your services in the Swagger UI with the new [Api("Service Description")] [Route("/swagger/{Name}", "GET", Summary = @"GET Summary", Notes = "GET Notes")] [Route("/swagger/{Name}", "POST", Summary = @"POST Summary", Notes = "POST Notes")] public class MyRequestDto { [ApiMember(Name="Name", Description = "Name Description", ParameterType = "path", DataType = "string", IsRequired = true)] public string Name { get; set; } } Provides ServiceStack's primary HTML story with support for the MVC Razor view engine. Plugins.Add(new RazorFormat()); It's an optional .NET 4.0 plugin that is available in the ServiceStack.Razor NuGet package. Enable the validation feature if you want to ensure all of ServiceStack's Fluent validators for Request DTOs Plugins.Add(new ValidationFeature()); More information on ServiceStack's built-in Fluent Validation support is described on the Validation page. The Authentication Feature enables the Authentication and Authorization support in ServiceStack. It makes available the AuthService at the default route at 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 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. 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. Related to Authentication is Registration which enables the Registration Service at the default route Plugins.Add(new RegistrationFeature()); See the SocialBootstrapApi project for a working example of Registration and Authentication. To add fast binary MessagePack support to ServiceStack install the ServiceStack.Plugins.MsgPack NuGet package and register the plugin with: Plugins.Add(new MsgPackFormat()); To enable ProtoBuf support install the ServiceStack.Plugins.ProtoBuf NuGet package and register the plugin with: Plugins.Add(new ProtoBufFormat()); Add an In-Memory Plugins.Add(new RequestLogsFeature()); The It supports multiple queryString filters and switches so you filter out related requests for better analysis and debuggability: The RequestLogsService is just a simple C# service under-the-hood but is a good example of how a little bit of code can provide a lot of value in ServiceStack's by leveraging its generic, built-in features. The Encrypted Messaging feature enables a secure channel for all Services to offer protection to clients who can now easily send and receive encrypted messages over unsecured HTTP by registering the EncryptedMessagesFeature plugin: Plugins.Add(new EncryptedMessagesFeature { PrivateKeyXml = ServerRsaPrivateKeyXml }); Where The Cancellable Requests Feature makes it easy to design long-running Services that are cancellable with an external Web Service Request. To enable this feature, register the CancellableRequestsFeature plugin: Plugins.Add(new CancellableRequestsFeature()); A common UX in some websites is to add an extra layer of protection for super protected functionality by getting users to re-confirm their password verifying it's still them using the website, common in places like confirming a financial transaction. WebSudo is a new feature similar in spirit requiring users to re-authenticate when accessing Services annotated with the Plugins.Add(new WebSudoFeature()); Your Custom AuthUserSession would need to either inherit public class CustomUserSession : WebSudoAuthUserSession {} Then tell ServiceStack to use your CustomUserSession by registering it with the Plugins.Add(new AuthFeature(() => new CustomUserSession(), ...); You can then apply WebSudo behavior to existing services by annotating them with [WebSudoRequired] public class RequiresWebSudoService : Service { public object Any(RequiresWebSudo request) { return request; } } Once enabled this will throw a 402 Web Sudo Required HTTP Error the first time the service is called: var requiresWebSudo = new RequiresWebSudo { Name = "test" }; try { client.Send<RequiresWebSudoResponse>(requiresWebSudo); //throws } catch (WebServiceException) { client.Send(authRequest); //re-authenticate var response = client.Send(requiresWebSudo); //success! } Re-authenticating afterwards will allow access to the WebSudo service.
Clone this wiki locally |
| You are visitor 01402775 — 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. |