Skip to content

Instantly share code, notes, and snippets.

View thecodejunkie's full-sized avatar

Andreas Håkansson thecodejunkie

View GitHub Profile
@thecodejunkie
thecodejunkie / gist:803269
Created January 30, 2011 21:30
What INancyModule interface would look like if extracted from NancyModule
public interface INancyModule
{
/// <summary>
/// Gets or sets an <see cref="ITemplateEngineSelector"/> which represents the current application context
/// </summary>
ITemplateEngineSelector TemplateEngineSelector { get; set; }
/// <summary>
/// Gets <see cref="RouteDictionary"/> for declaring actions for DELETE requests.
/// </summary>
@thecodejunkie
thecodejunkie / gist:812478
Created February 5, 2011 14:08
Need to change my resharper settings
this is where I am at atm
Get["/test"] = x => {
return 1;
};
var asm = new FakeAssembly(x => {
x.AddResource("foo", "bar");
x.AddResource("bar", "foo");
});
public class FakeAssembly : Assembly
{
private readonly NameValueCollection resources = new NameValueCollection();
public FakeAssembly()
at TinyIoC.TinyIoCContainer.ResolveInternal(TypeRegistration registration, NamedParameterOverloads parameters, ResolveOptions options) in D:\My Dropbox\Development\Repositories\Nancy\src\Nancy\TinyIoc\TinyIoC.cs:line 2822
at TinyIoC.TinyIoCContainer.<ResolveAllInternal>d__3b.MoveNext() in D:\My Dropbox\Development\Repositories\Nancy\src\Nancy\TinyIoc\TinyIoC.cs:line 3095
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at TinyIoC.TinyIoCContainer.<ResolveAll>d__4`1.MoveNext() in D:\My Dropbox\Development\Repositories\Nancy\src\Nancy\TinyIoc\TinyIoC.cs:line 1857
at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()
at TinyIoC.TinyIoCContainer.ConstructType(Type type, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options) in D:\My Dropbox\Development\Repositories\Nancy\src\Nancy\TinyIoc\TinyIoC.cs:line 3032
at TinyIoC.TinyIoCContainer.ConstructType(Type type, ConstructorInfo constructor, ResolveOptions options) in D:\My Dropbox\
namespace Nancy
{
using System;
using System.Collections.Generic;
using System.Linq;
using Nancy.ViewEngines;
using TinyIoC;
using Nancy.Bootstrapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Collections.Specialized;
using System.Data;
using System.Configuration;
@thecodejunkie
thecodejunkie / gist:827307
Created February 15, 2011 09:25
Experimenting with new Nancy view engine signature
public Action<Stream> RenderView<TModel>(ViewLocationResult viewLocationResult, TModel model)
{
return stream =>
{
var templateManagerProvider =
new TemplateManagerProvider()
.WithLoader(new TemplateLoader(viewLocationResult.Contents));
var templateManager =
templateManagerProvider.GetNewManager();
@thecodejunkie
thecodejunkie / UnityViewFactory.cs
Created February 17, 2011 07:53
Workaround for Unitys limitation on IEnumerable<T> dependencies
/// <summary>
/// This class provides a workaround for Unitys lack of support for <see cref="IEnumerable{T}"/> dependencies. No additional
/// functionality should be added to this type.
/// </summary>
public sealed class UnityViewFactory : DefaultViewFactory
{
/// <summary>
/// The <see cref="Type"/> of the <see cref="UnityViewFactory"/> type.
/// </summary>
public static Type UnityViewFactoryType = typeof(UnityViewFactory);
@thecodejunkie
thecodejunkie / SparkViewEngine.cs
Created February 17, 2011 21:58
Uses <TModel> to convert the call from dynamic to TModel
private ViewEngineResult RenderView<TModel>(string path, TModel model)
{
var viewName =
Path.GetFileNameWithoutExtension(path);
var viewPath =
Path.GetDirectoryName(path);
var targetNamespace = string.Empty; //TODO Rob G: This can be used to support things like areas or features
this.ViewFolder = new FileSystemViewFolder(viewPath);
@thecodejunkie
thecodejunkie / gist:833391
Created February 18, 2011 07:49
Get file name + extension from a resource name
static string GetResourceFileName(string resourceName)
{
var nameSegments =
resourceName.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
var segmentCount =
nameSegments.Count();
return (segmentCount < 2) ?
string.Empty :