Skip to content

Instantly share code, notes, and snippets.

@MatthewBarker
Created March 31, 2016 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthewBarker/ea39848d9e30592c5b384aa179a9d84a to your computer and use it in GitHub Desktop.
Save MatthewBarker/ea39848d9e30592c5b384aa179a9d84a to your computer and use it in GitHub Desktop.
Automap service behaviour
namespace WcfService
{
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using Logic.Mappers;
/// <summary>
/// Registers AutoMapper for the calls to business logic methods.
/// </summary>
public class AutomapServiceBehavior : IServiceBehavior
{
/// <summary>
/// The mapper configuration
/// </summary>
private IMapperConfig mapperConfig;
/// <summary>
/// Initializes a new instance of the <see cref="AutomapServiceBehavior"/> class.
/// </summary>
/// <param name="mapperConfig">The mapper configuration.</param>
public AutomapServiceBehavior(IMapperConfig mapperConfig)
{
this.mapperConfig = mapperConfig;
}
/// <summary>
/// Provides the ability to pass custom data to binding elements to support the contract implementation.
/// </summary>
/// <param name="serviceDescription">The service description of the service.</param>
/// <param name="serviceHostBase">The host of the service.</param>
/// <param name="endpoints">The service endpoints.</param>
/// <param name="bindingParameters">Custom objects to which binding elements have access.</param>
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
this.mapperConfig.RegisterMap();
}
/// <summary>
/// Provides the ability to change run-time property values or insert custom extension objects such as error handlers, message or parameter interceptors, security extensions, and other custom extension objects.
/// </summary>
/// <param name="serviceDescription">The service description.</param>
/// <param name="serviceHostBase">The host that is currently being built.</param>
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
{
}
/// <summary>
/// Provides the ability to inspect the service host and the service description to confirm that the service can run successfully.
/// </summary>
/// <param name="serviceDescription">The service description.</param>
/// <param name="serviceHostBase">The service host that is currently being constructed.</param>
public void Validate(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment