CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets for: TheCodeJunkie
C#
namespace Nancy.Formatters
{
    using System;
    using System.IO;
    using Newtonsoft.Json;
 
    public static class JsonFormatterExtensions
    {
        public static Response Json<TModel>(this IResponseFormatter response, TModel model)
        {
by TheCodeJunkie   December 14, 2010 @ 11:09pm
Tags:
238 Views
no comments
 
C#
Get["/static"] = parameters => {
   return View.Static("~/views/index.htm");
};
by TheCodeJunkie   December 11, 2010 @ 9:04am
Tags:
182 Views
no comments
 
C#
public Response Foo()
{
    return new FakeEntity();  // C# wont let me do this with implicit cast operators
}
by TheCodeJunkie   December 08, 2010 @ 1:59pm
Tags:
130 Views
1 comments
 
C#
public class Index : NancyModule
{
   public Index()
   {
      Get["/"] = x => {
         return "hi";
      };
   }
}
by TheCodeJunkie   December 08, 2010 @ 10:48am
Tags:
94 Views
no comments
 
XML
nancy.nuspec
 
<?xml version="1.0"?>
<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>Nancy</id>
    <version>0.0.0.1</version>
    <authors>Andreas H&#229;kansson</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Nancy is a lightweight web framework for the .Net platform, inspired by Sinatra. Nancy aim at delivering a low ceremony approach to building light, fast web applications.</description>
by TheCodeJunkie   December 06, 2010 @ 11:51pm
Tags:
308 Views
no comments
 
C#
[Fact]
public void Should_return_not_found_response_when_no_nancy_modules_could_be_found()
{
    // Given
    var request = new Request("GET", "/");
 
    A.CallTo(() => this.locator.GetModules()).Returns(Enumerable.Empty<NancyModule>());
 
    // When
    var response = this.engine.HandleRequest(request);
by TheCodeJunkie   November 27, 2010 @ 2:38pm
Tags:
129 Views
no comments
 
C#
public abstract class RequestSpec
{
    protected static IEngine engine;
    protected static IRequest request;
    protected static IResponse response;
 
    protected RequestSpec()
    {
        engine = new Engine();
    }
by TheCodeJunkie   November 21, 2010 @ 3:34pm
Tags:
84 Views
no comments
 
C#
[Subject("Handling a GET request")]
public class when_get_request_matched_existing_route
{
    static IEngine engine;
    static IRequest request;
    static IResponse response;
 
    Establish context = () =>
    {
        request = new Request("GET", new Uri("/"));
by TheCodeJunkie   November 21, 2010 @ 3:24pm
Tags:
88 Views
no comments
 
C#
public class Container : IContainer
{
    private readonly Dictionary<Type, Func<IContainer, object>> registrations = new Dictionary<Type, Func<IContainer, object>>();
 
    public void Register<T>(Func<IContainer, object> resolver)
    {
        this.registrations.Add(typeof(T), resolver);
    }
 
    public void RegisterSingleton<T>(Func<IContainer, object> resolver)
by TheCodeJunkie   November 16, 2010 @ 4:15am
Tags:
92 Views
no comments
 
C#
public class Bootstrapper
{
    public ShellPresentationModel Main { get; private set; }
    
    public static void Run()
    {
        var locator =
            new PartRegistryLocator(new[] { new ExtensionRegistry() });
 
        var conventionCatalog = new ConventionCatalog(locator);
by TheCodeJunkie   November 07, 2010 @ 11:11pm
Tags:
124 Views
no comments
 
C#
Get["/"] = x => {
    return "This is the root";
};
 
Get["/Greet"] = x => {
    return "Hello World";
};
 
Get["/Greet/{name}"] = x => {
    return "Hello " + x.name;
by TheCodeJunkie   September 01, 2010 @ 1:23am
Tags:
83 Views
no comments
 
C#
R#5 wants to turn
 
var creator =
    new ConventionPartCreator(registry);
 
into
 
var creator = new ConventionPartCreator(registry);
 
how do I make it stop!?
by TheCodeJunkie   June 10, 2010 @ 11:22am
Tags:
157 Views
no comments
 
C#
public class TestRegistry
{
    public TestRegistry()
    {
        Defaults(x => {
            x.Type<Foo>().Contract("Andreas").Identity<IWidget>();
            x.Type<Bar>().Contract("Piotr").Identity<IUnity>();
        });
 
        Part()
by TheCodeJunkie   May 25, 2010 @ 5:07am
Tags:
158 Views
no comments
 
properties {
    $base_directory   = resolve-path .
    $build_directory  = "$base_directory\release"
    $source_directory = "$base_directory\src"
    $tools_directory  = "$base_directory\tools"
    $version          = "1.0.0.0"
}
 
include .\psake_ext.ps1
by TheCodeJunkie   May 15, 2010 @ 8:21am
Tags:
373 Views
no comments
 
C#
public static class Member
{
    /// <summary>
    /// Retrieves the member that an expression is defined for.
    /// </summary>
    /// <param name="expression">The expression to retreive the member from.</param>
    /// <returns>A <see cref="MemberInfo"/> instance if the member could be found; otherwise <see langword="null"/>.</returns>
    private static MemberInfo GetTargetMemberInfo(this Expression expression)
    {
        switch (expression.NodeType)
by TheCodeJunkie   April 12, 2010 @ 10:13pm
Tags:
204 Views
no comments
 
C#
public interface IRuleMetadata
{
    [DefaultValue(0)]
    int ExecutionOrder { get; }
}
 
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class RuleAttribute : ExportAttribute, IRuleMetadata
{
    public RuleAttribute(int executionOrder)
by TheCodeJunkie   February 13, 2010 @ 3:30pm
Tags: MEF
747 Views
no comments
 
C#
public class LoggerRegistry : PartRegistry
{
    public LoggerRegistry()
    {
        Part<PartConvention>()
            .ForTypesMatching(x => x.GetInterfaces().Contains(typeof(ILogger)))
            .Exports(x => x.Export<ExportConvention>()
                .ContractType<ILogger>()
                .ContractName<ILogger>()
                .Members(m => new[] { m }))
by TheCodeJunkie   February 08, 2010 @ 2:38pm
Tags: MEF
247 Views
no comments
 
C#
public class ConventionPart<T> : IPartImportsSatisfiedNotification
{
    /// <summary>
    /// Initializes a new instance of the <see cref="ConventionPart{T}"/> class.
    /// </summary>
    public ConventionPart()
    {
    }
 
    [ImportMany]
by TheCodeJunkie   February 07, 2010 @ 3:14pm
Tags: MEF
340 Views
no comments
 
C#
public class FakeConventionRegistry :  ConventionRegistry
{
    public FakeConventionRegistry()
    {
        Part<PartConvention>()
            .ForTypesMatching(x => x.IsPublic && x.IsAbstract == false)
            .MakeShared()
            .Imports(x =>
            {
                x.Import<ImportConvention>()
by TheCodeJunkie   February 01, 2010 @ 1:33pm
Tags:
144 Views
no comments
 
C#
public class MyConventionRegistry : ConventionRegistry
{
    public MyConventionRegistry()
    {
        Part<PartConvention>()
            .ForTypesMatching(x => x.Name.StartsWith("Foo"))
            .MakeNonShared()
            .Imports(i =>
            {
                i.Import<ImportConvention>().As<IImportConvention>();
by TheCodeJunkie   February 01, 2010 @ 2:08am
Tags:
171 Views
no comments
 
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate