Skip to main content

IAppHost

ASP.NET or HttpListener ServiceStack host

Assembly: ServiceStack.dll
View Source
Declaration
public interface IAppHost : IResolver

Properties

PathBase

The base path ServiceStack is hosted on

View Source
Declaration
string PathBase { get; }

ServiceAssemblies

The assemblies reflected to find api services provided in the AppHost constructor

View Source
Declaration
List<Assembly> ServiceAssemblies { get; }

OnEndRequestCallbacks

Register callbacks to be called at the end of each request.

View Source
Declaration
List<Action<IRequest>> OnEndRequestCallbacks { get; }

Routes

Register user-defined custom routes.

View Source
Declaration
IServiceRoutes Routes { get; }

Metadata

Inferred Metadata available from existing services

View Source
Declaration
ServiceMetadata Metadata { get; }

ContentTypes

Register custom ContentType serializers

View Source
Declaration
IContentTypes ContentTypes { get; }

PreRequestFilters

Add Request Filters, to be applied before the dto is deserialized

View Source
Declaration
List<Action<IRequest, IResponse>> PreRequestFilters { get; }

RequestConverters

Add Request Converter to convert Request DTO's

View Source
Declaration
List<Func<IRequest, object, Task<object>>> RequestConverters { get; }

ResponseConverters

Add Response Converter to convert Response DTO's

View Source
Declaration
List<Func<IRequest, object, Task<object>>> ResponseConverters { get; }

GlobalRequestFilters

Add Request Filters for HTTP Requests

View Source
Declaration
List<Action<IRequest, IResponse, object>> GlobalRequestFilters { get; }

GlobalRequestFiltersAsync

Add Async Request Filters for HTTP Requests

View Source
Declaration
List<Func<IRequest, IResponse, object, Task>> GlobalRequestFiltersAsync { get; }

GlobalResponseFilters

Add Response Filters for HTTP Responses

View Source
Declaration
List<Action<IRequest, IResponse, object>> GlobalResponseFilters { get; }

GlobalResponseFiltersAsync

Add Async Response Filters for HTTP Responses

View Source
Declaration
List<Func<IRequest, IResponse, object, Task>> GlobalResponseFiltersAsync { get; set; }

GlobalMessageRequestFilters

Add Request Filters for MQ/TCP Requests

View Source
Declaration
List<Action<IRequest, IResponse, object>> GlobalMessageRequestFilters { get; }

GlobalMessageRequestFiltersAsync

Add Async Request Filters for MQ/TCP Requests

View Source
Declaration
List<Func<IRequest, IResponse, object, Task>> GlobalMessageRequestFiltersAsync { get; }

GlobalMessageResponseFilters

Add Response Filters for MQ/TCP Responses

View Source
Declaration
List<Action<IRequest, IResponse, object>> GlobalMessageResponseFilters { get; }

GlobalMessageResponseFiltersAsync

Add Async Response Filters for MQ/TCP Responses

View Source
Declaration
List<Func<IRequest, IResponse, object, Task>> GlobalMessageResponseFiltersAsync { get; }

GatewayRequestFilters

Add Request Filter for Service Gateway Requests

View Source
Declaration
List<Action<IRequest, object>> GatewayRequestFilters { get; }

GatewayRequestFiltersAsync

Add Async Request Filter for Service Gateway Requests

View Source
Declaration
List<Func<IRequest, object, Task>> GatewayRequestFiltersAsync { get; }

GatewayResponseFilters

Add Response Filter for Service Gateway Responses

View Source
Declaration
List<Action<IRequest, object>> GatewayResponseFilters { get; }

GatewayResponseFiltersAsync

Add Async Response Filter for Service Gateway Responses

View Source
Declaration
List<Func<IRequest, object, Task>> GatewayResponseFiltersAsync { get; }

ViewEngines

Add alternative HTML View Engines

View Source
Declaration
List<IViewEngine> ViewEngines { get; }

ServiceExceptionHandlers

Provide an exception handler for unhandled exceptions

View Source
Declaration
List<HandleServiceExceptionDelegate> ServiceExceptionHandlers { get; }

ServiceExceptionHandlersAsync

Provide an exception handler for unhandled exceptions (Async)

View Source
Declaration
List<HandleServiceExceptionAsyncDelegate> ServiceExceptionHandlersAsync { get; }

UncaughtExceptionHandlers

Provide an exception handler for un-caught exceptions

View Source
Declaration
List<HandleUncaughtExceptionDelegate> UncaughtExceptionHandlers { get; }

UncaughtExceptionHandlersAsync

Provide an exception handler for un-caught exceptions (Async)

View Source
Declaration
List<HandleUncaughtExceptionAsyncDelegate> UncaughtExceptionHandlersAsync { get; }

GatewayExceptionHandlers

Provide an exception handler for Service Gateway Exceptions

View Source
Declaration
List<HandleGatewayExceptionDelegate> GatewayExceptionHandlers { get; }

GatewayExceptionHandlersAsync

Provide an exception handler for Service Gateway Exceptions (Async)

View Source
Declaration
List<HandleGatewayExceptionAsyncDelegate> GatewayExceptionHandlersAsync { get; }

BeforeConfigure

Register callbacks fired just before AppHost.Configure()

View Source
Declaration
List<Action<ServiceStackHost>> BeforeConfigure { get; set; }

AfterConfigure

Register callbacks fired just after AppHost.Configure()

View Source
Declaration
List<Action<ServiceStackHost>> AfterConfigure { get; set; }

AfterPluginsLoaded

Register callbacks to be fired after all plugins are loaded

View Source
Declaration
List<Action<ServiceStackHost>> AfterPluginsLoaded { get; set; }

AfterInitCallbacks

Register callbacks to be fired after the AppHost has finished initializing

View Source
Declaration
List<Action<IAppHost>> AfterInitCallbacks { get; }

OnDisposeCallbacks

Register callbacks to be fired when AppHost is being disposed

View Source
Declaration
List<Action<IAppHost>> OnDisposeCallbacks { get; }

RawHttpHandlers

Skip the ServiceStack Request Pipeline and process the returned IHttpHandler instead

View Source
Declaration
List<Func<IHttpRequest, IHttpHandler>> RawHttpHandlers { get; }

CatchAllHandlers

Provide a catch-all handler that doesn't match any routes

View Source
Declaration
List<HttpHandlerResolverDelegate> CatchAllHandlers { get; }

FallbackHandlers

Provide a fallback handler for not found requests (last filter in Request Pipeline)

View Source
Declaration
List<HttpHandlerResolverDelegate> FallbackHandlers { get; }

GlobalHtmlErrorHttpHandler

Use a fall-back Error Handler for handling global errors

View Source
Declaration
IServiceStackHandler GlobalHtmlErrorHttpHandler { get; }

CustomErrorHttpHandlers

Use a Custom Error Handler for handling specific error HttpStatusCodes

View Source
Declaration
Dictionary<HttpStatusCode, IServiceStackHandler> CustomErrorHttpHandlers { get; }

RequestBinders

Provide a custom model minder for a specific Request DTO

View Source
Declaration
Dictionary<Type, Func<IRequest, object>> RequestBinders { get; }

Config

The AppHost config

View Source
Declaration
HostConfig Config { get; }

AppSettings

The AppHost AppSettings. Defaults to App or Web.config appSettings.

View Source
Declaration
IAppSettings AppSettings { get; }

Plugins

List of pre-registered and user-defined plugins to be enabled in this AppHost

View Source
Declaration
List<IPlugin> Plugins { get; }

VirtualFileSources

Cascading number of file sources, inc. Embedded Resources, File System, In Memory, S3

View Source
Declaration
IVirtualPathProvider VirtualFileSources { get; set; }

VirtualFiles

Read/Write Virtual FileSystem. Defaults to FileSystemVirtualPathProvider

View Source
Declaration
IVirtualFiles VirtualFiles { get; set; }

RootDirectory

The WebRoot VFS Directory of the cascading VirtualFileSources

View Source
Declaration
IVirtualDirectory RootDirectory { get; }

ContentRootDirectory

The ContentRoot VFS Directory of the read/write VirtualFiles Provider

View Source
Declaration
IVirtualDirectory ContentRootDirectory { get; }

InsertVirtualFileSources

Insert Virtual File Sources at the beginning so they take precedence over built-in sources

View Source
Declaration
List<IVirtualPathProvider> InsertVirtualFileSources { get; set; }

AddVirtualFileSources

Add additional Virtual File Sources at the end after built-in Virtual File Sources

View Source
Declaration
List<IVirtualPathProvider> AddVirtualFileSources { get; }

ServiceController

Access Service Controller for ServiceStack

View Source
Declaration
ServiceController ServiceController { get; }

ScriptContext

Global #Script ScriptContext for AppHost. Returns SharpPagesFeature plugin or fallsback to DefaultScriptContext.

View Source
Declaration
ScriptContext ScriptContext { get; }

Methods

Register<T>(T)

Register dependency in AppHost IOC on Startup

View Source
Declaration
void Register<T>(T instance)
Parameters
TypeName
<T>instance
Type Parameters
  • T

RegisterAs<T, TAs>()

AutoWired Registration of an interface with a concrete type in AppHost IOC on Startup.

View Source
Declaration
void RegisterAs<T, TAs>()
where T : TAs
Type Parameters
  • T
  • TAs

Release(Object)

Allows the clean up for executed autowired services and filters. Calls directly after services and filters are executed.

View Source
Declaration
void Release(object instance)
Parameters
TypeName
System.Objectinstance

OnEndRequest(IRequest)

Called at the end of each request. Enables Request Scope.

View Source
Declaration
void OnEndRequest(IRequest request = null)
Parameters
TypeName
ServiceStack.Web.IRequestrequest

RegisterTypedRequestFilter<T>(Action<IRequest, IResponse, T>)

Add Request Filter for a specific Request DTO Type

View Source
Declaration
void RegisterTypedRequestFilter<T>(Action<IRequest, IResponse, T> filterFn)
Parameters
TypeName
System.Action<ServiceStack.Web.IRequest,ServiceStack.Web.IResponse,<T>>filterFn
Type Parameters
  • T

RegisterTypedRequestFilterAsync<T>(Func<IRequest, IResponse, T, Task>)

Add an Async Request Filter for a specific Request DTO Type

View Source
Declaration
void RegisterTypedRequestFilterAsync<T>(Func<IRequest, IResponse, T, Task> filterFn)
Parameters
TypeName
System.Func<ServiceStack.Web.IRequest,ServiceStack.Web.IResponse,<T>,System.Threading.Tasks.Task>filterFn
Type Parameters
  • T

RegisterTypedRequestFilter<T>(Func<Container, ITypedFilter<T>>)

Add ServiceStack.Host.ITypedFilter%601 as a Typed Request Filter for a specific Request DTO Type

View Source
Declaration
void RegisterTypedRequestFilter<T>(Func<Container, ITypedFilter<T>> filter)
Parameters
TypeNameDescription
System.Func<Funq.Container,ServiceStack.Host.ITypedFilter<<T>>>filterThe Funq.Container methods to resolve the ServiceStack.Host.ITypedFilter%601.

|

Type Parameters
NameDescription
TThe DTO Type.

RegisterTypedRequestFilterAsync<T>(Func<Container, ITypedFilterAsync<T>>)

Add ServiceStack.Host.ITypedFilterAsync%601 as an Async Typed Request Filter for a specific Request DTO Type

View Source
Declaration
void RegisterTypedRequestFilterAsync<T>(Func<Container, ITypedFilterAsync<T>> filter)
Parameters
TypeNameDescription
System.Func<Funq.Container,ServiceStack.Host.ITypedFilterAsync<<T>>>filterThe Funq.Container methods to resolve the ServiceStack.Host.ITypedFilterAsync%601.

|

Type Parameters
NameDescription
TThe DTO Type.

RegisterTypedResponseFilter<T>(Action<IRequest, IResponse, T>)

Add Request Filter for a specific Response DTO Type

View Source
Declaration
void RegisterTypedResponseFilter<T>(Action<IRequest, IResponse, T> filterFn)
Parameters
TypeName
System.Action<ServiceStack.Web.IRequest,ServiceStack.Web.IResponse,<T>>filterFn
Type Parameters
  • T

RegisterTypedResponseFilterAsync<T>(Func<IRequest, IResponse, T, Task>)

Add an Async Request Filter for a specific Response DTO Type

View Source
Declaration
void RegisterTypedResponseFilterAsync<T>(Func<IRequest, IResponse, T, Task> filterFn)
Parameters
TypeName
System.Func<ServiceStack.Web.IRequest,ServiceStack.Web.IResponse,<T>,System.Threading.Tasks.Task>filterFn
Type Parameters
  • T

RegisterTypedResponseFilter<T>(Func<Container, ITypedFilter<T>>)

Add ServiceStack.Host.ITypedFilter%601 as a Typed Request Filter for a specific Request DTO Type

View Source
Declaration
void RegisterTypedResponseFilter<T>(Func<Container, ITypedFilter<T>> filter)
Parameters
TypeNameDescription
System.Func<Funq.Container,ServiceStack.Host.ITypedFilter<<T>>>filterThe Funq.Container methods to resolve the ServiceStack.Host.ITypedFilter%601.

|

Type Parameters
NameDescription
TThe DTO Type.

RegisterTypedResponseFilterAsync<T>(Func<Container, ITypedFilterAsync<T>>)

Add ServiceStack.Host.ITypedFilterAsync%601 as an Async Typed Request Filter for a specific Request DTO Type

View Source
Declaration
void RegisterTypedResponseFilterAsync<T>(Func<Container, ITypedFilterAsync<T>> filter)
Parameters
TypeNameDescription
System.Func<Funq.Container,ServiceStack.Host.ITypedFilterAsync<<T>>>filterThe Funq.Container methods to resolve the ServiceStack.Host.ITypedFilterAsync%601.

|

Type Parameters
NameDescription
TThe DTO Type.

RegisterTypedMessageRequestFilter<T>(Action<IRequest, IResponse, T>)

Add Request Filter for a specific MQ Request DTO Type

View Source
Declaration
void RegisterTypedMessageRequestFilter<T>(Action<IRequest, IResponse, T> filterFn)
Parameters
TypeName
System.Action<ServiceStack.Web.IRequest,ServiceStack.Web.IResponse,<T>>filterFn
Type Parameters
  • T

RegisterTypedMessageResponseFilter<T>(Action<IRequest, IResponse, T>)

Add Request Filter for a specific MQ Response DTO Type

View Source
Declaration
void RegisterTypedMessageResponseFilter<T>(Action<IRequest, IResponse, T> filterFn)
Parameters
TypeName
System.Action<ServiceStack.Web.IRequest,ServiceStack.Web.IResponse,<T>>filterFn
Type Parameters
  • T

GetRuntimeConfig<T>(IRequest, String, T)

Allow specific configuration to be overridden at runtime in multi-tenancy Applications by overriding GetRuntimeConfig in your AppHost

View Source
Declaration
T GetRuntimeConfig<T>(IRequest req, string name, T defaultValue)
Returns

<T>

Parameters
TypeName
ServiceStack.Web.IRequestreq
System.Stringname
<T>defaultValue
Type Parameters
  • T

RegisterService(Type, String[])

Register an Adhoc web service on Startup

View Source
Declaration
void RegisterService(Type serviceType, params string[] atRestPaths)
Parameters
TypeName
System.TypeserviceType
System.String[]atRestPaths

RegisterServicesInAssembly(Assembly)

Register all Services in Assembly

View Source
Declaration
void RegisterServicesInAssembly(Assembly assembly)
Parameters
TypeName
System.Reflection.Assemblyassembly

LoadPlugin(IPlugin[])

Apply plugins to this AppHost

View Source
Declaration
void LoadPlugin(params IPlugin[] plugins)
Parameters
TypeName
ServiceStack.IPlugin[]plugins

MapProjectPath(String)

Returns the Absolute File Path, relative from your AppHost's Project Path

View Source
Declaration
string MapProjectPath(string relativePath)
Returns

System.String

Parameters
TypeName
System.StringrelativePath

CreateServiceRunner<TRequest>(ActionContext)

Create a service runner for IService actions

View Source
Declaration
IServiceRunner<TRequest> CreateServiceRunner<TRequest>(ActionContext actionContext)
Returns

ServiceStack.Web.IServiceRunner<TRequest>

Parameters
TypeName
ServiceStack.Host.ActionContextactionContext
Type Parameters
  • TRequest

ResolveAbsoluteUrl(String, IRequest)

Resolve the absolute url for this request

View Source
Declaration
string ResolveAbsoluteUrl(string virtualPath, IRequest httpReq)
Returns

System.String

Parameters
TypeName
System.StringvirtualPath
ServiceStack.Web.IRequesthttpReq

ResolveLocalizedString(String, IRequest)

Resolve localized text, returns itself by default. The Request is provided when exists.

View Source
Declaration
string ResolveLocalizedString(string text, IRequest request)
Returns

System.String

Parameters
TypeName
System.Stringtext
ServiceStack.Web.IRequestrequest

ExecuteMessage(IMessage)

Execute MQ Message in ServiceStack

View Source
Declaration
object ExecuteMessage(IMessage mqMessage)
Returns

System.Object

Parameters
TypeName
ServiceStack.Messaging.IMessagemqMessage

ExecuteMessageAsync(IMessage, CancellationToken)

Execute MQ Message in ServiceStack

View Source
Declaration
Task<object> ExecuteMessageAsync(IMessage mqMessage, CancellationToken token = default(CancellationToken))
Returns

System.Threading.Tasks.Task<System.Object>

Parameters
TypeName
ServiceStack.Messaging.IMessagemqMessage
System.Threading.CancellationTokentoken

PublishMessage<T>(IMessageProducer, T)

Publish Message to be processed by AppHost

View Source
Declaration
void PublishMessage<T>(IMessageProducer messageProducer, T message)
Parameters
TypeName
ServiceStack.Messaging.IMessageProducermessageProducer
<T>message
Type Parameters
  • T

EvalExpression(String)

Evaluate Expressions in ServiceStack's ScriptContext. Can be overridden if you want to customize how different expressions are evaluated.

View Source
Declaration
object EvalExpression(string expr)
Returns

System.Object

Parameters
TypeName
System.Stringexpr

EvalExpressionCached(String)

Evaluate Expressions in ServiceStack's ScriptContext. Can be overridden if you want to customize how different expressions are evaluated.

View Source
Declaration
object EvalExpressionCached(string expr)
Returns

System.Object

Parameters
TypeName
System.Stringexpr

EvalScriptValue(IScriptValue, IRequest, Dictionary<String, Object>)

Evaluate a script value, IScriptValue.Expression results are cached globally. If IRequest is provided, results from the same IScriptValue.Eval are cached per request.

View Source
Declaration
object EvalScriptValue(IScriptValue scriptValue, IRequest req = null, Dictionary<string, object> args = null)
Returns

System.Object

Parameters
TypeName
ServiceStack.IScriptValuescriptValue
ServiceStack.Web.IRequestreq
System.Collections.Generic.Dictionary<System.String,System.Object>args

EvalScriptValueAsync(IScriptValue, IRequest, Dictionary<String, Object>)

Evaluate a script value, IScriptValue.Expression results are cached globally. If IRequest is provided, results from the same IScriptValue.Eval are cached per request.

View Source
Declaration
Task<object> EvalScriptValueAsync(IScriptValue scriptValue, IRequest req = null, Dictionary<string, object> args = null)
Returns

System.Threading.Tasks.Task<System.Object>

Parameters
TypeName
ServiceStack.IScriptValuescriptValue
ServiceStack.Web.IRequestreq
System.Collections.Generic.Dictionary<System.String,System.Object>args

ConfigurePlugin<T>(Action<T>)

Register a callback to configure a plugin just before it's registered

View Source
Declaration
void ConfigurePlugin<T>(Action<T> configure)
where T : class, IPlugin
Parameters
TypeName
System.Action<<T>>configure
Type Parameters
  • T

PostConfigurePlugin<T>(Action<T>)

Register a callback to configure a plugin just after it's registered

View Source
Declaration
void PostConfigurePlugin<T>(Action<T> configure)
where T : class, IPlugin
Parameters
TypeName
System.Action<<T>>configure
Type Parameters
  • T

AfterPluginLoaded<T>(Action<T>)

Register a callback to configure a plugin after AfterPluginsLoaded is run

View Source
Declaration
void AfterPluginLoaded<T>(Action<T> configure)
where T : class, IPlugin
Parameters
TypeName
System.Action<<T>>configure
Type Parameters
  • T