Permalink
Browse files

Allow Request/Response Filters for MessageHandlers.

Allow custom Model Binders to be specified for Request DTOs
  • Loading branch information...
mythz committed Feb 15, 2012
1 parent 496ecbd commit 43768e824b92b2fb52c7ff4b897be3b49a71be40
@@ -2,18 +2,22 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>ServiceStack.Client.Silverlight</id>
- <version>3.4.3</version>
+ <version>3.5.1</version>
<authors>Demis Bellot</authors>
<owners>Demis Bellot</owners>
<summary>Silverlight JSON, XML, JSV ServiceClients for ServiceStack web services</summary>
<description>
- ServiceStack client binaries for Silverlight. Provides generic JSON, XML and JSV Service Clients allowing you to call ServiceStack web services from a Silverlight client.
+ ServiceStack client binaries for Silverlight. Provides generic JSON, XML and JSV Service Clients allowing you to call ServiceStack web services from a Silverlight client.
+ This is now a stub that points to ServiceStack.Common NuGet package which now contains the Silverlight client builds.
</description>
<projectUrl>https://github.com/ServiceStack/ServiceStack</projectUrl>
<licenseUrl>https://github.com/ServiceStack/ServiceStack/blob/master/LICENSE</licenseUrl>
<iconUrl>http://www.servicestack.net/logo-100x100.png</iconUrl>
<tags>Silverlight Fast JSON XML JSV REST Web Services</tags>
<language>en-US</language>
<copyright>servicestack.net 2012 and contributors</copyright>
+ <dependencies>
+ <dependency id="ServiceStack.Common" />
+ </dependencies>
</metadata>
</package>
@@ -2,13 +2,16 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>ServiceStack</id>
- <version>3.4.8</version>
+ <version>3.5.1</version>
<authors>Demis Bellot</authors>
<owners>Demis Bellot</owners>
<summary>Opensource .NET and Mono REST Web Services framework</summary>
<description>
- Binaries for ServiceStack. New projects should reference host packages: *ServiceStack.Host.AspNet* (hosted at '/') or *ServiceStack.Host.Mvc* (hosted at '/api')
- </description>
+ Binaries for the ServiceStack web framework.
+ Visit http://www.servicestack.net/ServiceStack.Hello/
+ and https://github.com/ServiceStack/ServiceStack/wiki/Create-your-first-webservice
+ for walk throughs and docs on creating your first web service.
+ </description>
<projectUrl>https://github.com/ServiceStack/ServiceStack</projectUrl>
<licenseUrl>https://github.com/ServiceStack/ServiceStack/blob/master/LICENSE</licenseUrl>
<iconUrl>http://www.servicestack.net/logo-100x100.png</iconUrl>
View
@@ -5,14 +5,14 @@ SET BUILD=Release
REM %MSBUILD% build.msbuild
-COPY ..\src\ServiceStack.ServiceInterface\bin\%BUILD%\ServiceStack.dll ..\NuGet\ServiceStack\lib
-COPY ..\src\ServiceStack.ServiceInterface\bin\%BUILD%\ServiceStack.pdb ..\NuGet\ServiceStack\lib
-COPY ..\src\ServiceStack.ServiceInterface\bin\%BUILD%\ServiceStack.xml ..\NuGet\ServiceStack\lib
-COPY ..\src\ServiceStack.ServiceInterface\bin\%BUILD%\ServiceStack.ServiceInterface.* ..\NuGet\ServiceStack\lib
-COPY ..\src\ServiceStack.RazorEngine\bin\%BUILD%\ServiceStack.RazorEngine.* ..\NuGet\ServiceStack\lib
-
-COPY ..\src\ServiceStack.ServiceInterface\bin\%BUILD%\ServiceStack.Common.* ..\NuGet\ServiceStack.Common\lib
-COPY ..\src\ServiceStack.ServiceInterface\bin\%BUILD%\ServiceStack.Interfaces.* ..\NuGet\ServiceStack.Common\lib
+COPY ..\src\ServiceStack.ServiceInterface\bin\%BUILD%\ServiceStack.dll ..\NuGet\ServiceStack\lib\net35
+COPY ..\src\ServiceStack.ServiceInterface\bin\%BUILD%\ServiceStack.pdb ..\NuGet\ServiceStack\lib\net35
+COPY ..\src\ServiceStack.ServiceInterface\bin\%BUILD%\ServiceStack.xml ..\NuGet\ServiceStack\lib\net35
+COPY ..\src\ServiceStack.ServiceInterface\bin\%BUILD%\ServiceStack.ServiceInterface.* ..\NuGet\ServiceStack\lib\net35
+COPY ..\src\ServiceStack.RazorEngine\bin\%BUILD%\ServiceStack.RazorEngine.* ..\NuGet\ServiceStack\lib\net35
+
+COPY ..\src\ServiceStack.ServiceInterface\bin\%BUILD%\ServiceStack.Common.* ..\NuGet\ServiceStack.Common\lib\net35
+COPY ..\src\ServiceStack.ServiceInterface\bin\%BUILD%\ServiceStack.Interfaces.* ..\NuGet\ServiceStack.Common\lib\net35
COPY ..\src\ServiceStack.FluentValidation.Mvc3\bin\%BUILD%\ServiceStack.FluentValidation.Mvc3.* ..\NuGet\ServiceStack.Mvc\lib\net4
@@ -7,6 +7,10 @@ public class MessageHandlerFactory<T>
{
public const int DefaultRetryCount = 2; //Will be a total of 3 attempts
private readonly IMessageService messageService;
+
+ public Func<IMessage, IMessage> RequestFilter { get; set; }
+ public Func<object, object> ResponseFilter { get; set; }
+
private readonly Func<IMessage<T>, object> processMessageFn;
private readonly Action<IMessage<T>, Exception> processExceptionFn;
public int RetryCount { get; set; }
@@ -34,7 +38,24 @@ public MessageHandlerFactory(IMessageService messageService, Func<IMessage<T>, o
public IMessageHandler CreateMessageHandler()
{
- return new MessageHandler<T>(messageService, processMessageFn,
+ if (this.RequestFilter == null && this.ResponseFilter == null)
+ {
+ return new MessageHandler<T>(messageService, processMessageFn,
+ processExceptionFn, this.RetryCount);
+ }
+
+ return new MessageHandler<T>(messageService, msg =>
+ {
+ if (this.RequestFilter != null)
+ msg = (IMessage<T>) this.RequestFilter(msg);
+
+ var result = this.processMessageFn(msg);
+
+ if (this.ResponseFilter != null)
+ result = this.ResponseFilter(result);
+
+ return result;
+ },
processExceptionFn, this.RetryCount);
}
}
@@ -47,6 +47,11 @@ public T TryResolve<T>()
public List<HttpHandlerResolverDelegate> CatchAllHandlers { get; set; }
+ public Dictionary<Type, Func<IHttpRequest, object>> RequestBinders
+ {
+ get { throw new NotImplementedException(); }
+ }
+
public EndpointHostConfig Config { get; set; }
public void RegisterService(Type serviceType, params string[] atRestPaths)
@@ -61,6 +61,11 @@ public T TryResolve<T>()
public List<HttpHandlerResolverDelegate> CatchAllHandlers { get; private set; }
+ public Dictionary<Type, Func<IHttpRequest, object>> RequestBinders
+ {
+ get { throw new NotImplementedException(); }
+ }
+
public EndpointHostConfig Config { get; set; }
public void RegisterService(Type serviceType, params string[] atRestPaths)
@@ -130,6 +130,11 @@ public T TryResolve<T>()
return this.Container.TryResolve<T>();
}
+ public Dictionary<Type, Func<IHttpRequest, object>> RequestBinders
+ {
+ get { return EndpointHost.ServiceManager.ServiceController.RequestTypeFactoryMap; }
+ }
+
public IContentTypeFilter ContentTypeFilters
{
get
@@ -1,10 +1,18 @@
-namespace ServiceStack.WebHost.Endpoints
+using System;
+using ServiceStack.ServiceHost;
+
+namespace ServiceStack.WebHost.Endpoints
{
public static class AppHostExtensions
{
public static void RegisterService<TService>(this IAppHost appHost, params string[] atRestPaths)
{
appHost.RegisterService(typeof(TService), atRestPaths);
}
+
+ public static void RegisterRequestBinder<TRequest>(this IAppHost appHost, Func<IHttpRequest, object> binder)
+ {
+ appHost.RequestBinders[typeof(TRequest)] = binder;
+ }
}
}
@@ -249,6 +249,7 @@ private static string ExtractHandlerPathFromWebServerConfigurationXml(string raw
public ServiceManager ServiceManager { get; internal set; }
public IServiceController ServiceController { get { return ServiceManager.ServiceController; } }
+
public string MetadataPageBodyHtml { get; set; }
public string MetadataOperationPageBodyHtml { get; set; }
@@ -55,6 +55,11 @@ public interface IAppHost : IResolver
/// </summary>
List<HttpHandlerResolverDelegate> CatchAllHandlers { get; }
+ /// <summary>
+ /// Provide a custom model minder for a specific Request DTO
+ /// </summary>
+ Dictionary<Type, Func<IHttpRequest, object>> RequestBinders { get; }
+
/// <summary>
/// The AppHost config
/// </summary>
@@ -303,6 +303,11 @@ public IServiceRoutes Routes
get { return EndpointHost.Config.ServiceController.Routes; }
}
+ public Dictionary<Type, Func<IHttpRequest, object>> RequestBinders
+ {
+ get { return EndpointHost.ServiceManager.ServiceController.RequestTypeFactoryMap; }
+ }
+
public IContentTypeFilter ContentTypeFilters
{
get
@@ -79,6 +79,11 @@ public T TryResolve<T>()
public List<HttpHandlerResolverDelegate> CatchAllHandlers { get; set; }
+ public Dictionary<Type, Func<IHttpRequest, object>> RequestBinders
+ {
+ get { throw new NotImplementedException(); }
+ }
+
public EndpointHostConfig Config { get; set; }
public void RegisterService(Type serviceType, params string[] atRestPaths)

0 comments on commit 43768e8

Please sign in to comment.