Giter VIP home page Giter VIP logo

nancy.embeddedcontent's Introduction

Nancy.EmbeddedContent

A code utility to aid in serving embedded content over a Nancy application (on .NET 4). An example of what to do with this is shipping a dll containing static files instead of a bunch of static files.

Disclaimer: i've written this package because i'm stuck on .NET 4 for a while longer. Instead of using this project, i'd recommend using Microsoft.Owin.StaticFiles if your project can use .NET 4.5.

Usage

This is meant to be downloaded and included in your own source code. To utilize, clone this code, and import the project into your solution.

Views will be discovered automatically as long as the build action for each file you want served is set to Embedded Resource.

To serve embedded files as static content, you will have to add a static content convention to your bootstrapper:

public class Bootstrapper : DefaultNancyBootstrapper
{
    protected override void ConfigureConventions(NancyConventions nancyConventions)
    {
        nancyConventions.StaticContentsConventions.AddEmbeddedDirectory("/Content");
    }
}

nancy.embeddedcontent's People

Contributors

dependabot[bot] avatar jrsconfitto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

wildgenie hopla

nancy.embeddedcontent's Issues

Incorrect assembly searched for static contents when building in "Release" mode

I noticed that my embedded static content wasn't being served (all of them 404'd) whenever I built my solution in the "Release" build configuration and launched my site from outside of the debugger. I enabled Nancy's request tracing functionality and eventually discovered that it was trying to find my static resources in Nancy.dll instead of my assembly.

Ultimately this was due to the fact that I was using Nancy.EmbeddedContent.Conventions.StaticContentsConventionsExtensions.AddEmbeddedDirectory(this IList<Func<NancyContext, string, Response>>, string, string, params string[]) which attempts to infer the correct assembly by calling Assembly.GetCallingAssembly(). Unfortunately this method can behave in unexpected ways due to JIT compilation as stated by Microsoft from their documentation:

If the method that calls the GetCallingAssembly method is expanded inline by the just-in-time (JIT) compiler, or if its caller is expanded inline, the assembly that is returned by GetCallingAssembly may differ unexpectedly.

The workaround for me was to use the overloaded AddEmbeddedDirectory that takes an Assembly and explicitly pass in a reference to the assembly that housed my static content.

I believe that the other AddEmbeddedDirectory which relies on Assembly.GetCallingAssembly() should be deprecated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.