Skip to content

Instantly share code, notes, and snippets.

View scottlittlewood's full-sized avatar

Scott Littlewood scottlittlewood

  • Dundee, UK
View GitHub Profile
@scottlittlewood
scottlittlewood / NHibernateSessionPipelineContributor.cs
Created November 29, 2010 13:43
Shows a simple implementation of using an OpenRasta Pipeline Contributor to manage nHibernate Sessions on a per request basis
public class NHibernateSessionPipelineContributor : IPipelineContributor
{
private readonly IDependencyResolver _resolver;
public NHibernateSessionPipelineContributor(IDependencyResolver resolver)
{
_resolver = resolver;
}
public void Initialize(IPipeline pipelineRunner)
@scottlittlewood
scottlittlewood / NewtonsoftJsonCodec.cs
Created December 9, 2010 10:57
OpenRasta Json Codec using the Newtonsoft.Json library
[MediaType("application/json;q=0.5", "json")]
public class NewtonsoftJsonCodec : IMediaTypeReader, IMediaTypeWriter
{
public object Configuration { get; set; }
public object ReadFrom(IHttpEntity request, IType destinationType, string destinationName)
{
using(var streamReader = new StreamReader(request.Stream))
{
var ser = new JsonSerializer();
[MediaType("application/json")]
public class JsonFxCodec : IMediaTypeWriter, IMediaTypeReader
{
private readonly JsonWriter _writer;
private readonly JsonReader _reader;
public object Configuration { get; set; }
public JsonFxCodec()
{
var resolver = new CombinedResolverStrategy(
public class Program
{
public static void Main(string[] args)
{
var serviceNamespace = typeof (Service).Namespace;
HostFactory.Run(x =>
{
x.Service<IService>(s =>
{
public class HttpListenerHostWithConfiguration : HttpListenerHost
{
private readonly IConfigurationSource _configuration;
public HttpListenerHostWithConfiguration(IConfigurationSource configuration)
{
_configuration = configuration;
}
public override bool ConfigureRootDependencies(IDependencyResolver resolver)