Improve support for embedded resources and NuGet it up #1331
Conversation
cc @khellang |
OK, i found some guidance from this mailing list post that talks about wiring this all up via an |
OK, i've added a basic registrations class to the Nancy.Embedded stuff to make wiring up embedded views a little more automatic. While running a demo project, i ran into an issue described in the mailing list by @thecodejunkie where i only had one embedded view and hadn't added to the RootNamespaces property. This throws a
When i add another view, or add my namespace to the i don't think this is very SDHP. Someone like me will test it out on one view and see if it worked and probably be 😠. It seems (to me) like a common base case for someone to try out Embedding content. Should we try to fill in RootNamespaces automatically for someone? Or should we work on throwing a nicer error so that someone can catch this issue quickly? i think at least a 500 would be better. i think i'll try to go down that route unless i hear different. |
Juggling - not sure if this is applicable to your extensions or not; I am having a pig of a time getting my Nancy.Test.csproj to load my embedded resource views for testing. The views exist in a separate App.UI assembly (which is separate from my App.Nancy assembly) ; I forcibly load the App.UI assembly into the NUnit execution AppDomain at runtime. Mostly weird because everything is peachy when I F5 the actual application (after implementing #1332 ) -- views are picked up and served as expected, just not within the testing context. My NancyModules can't bind the view even though its resource path is registered with its parent assembly via ResourceViewLocationProvider.RootNamespaces.Add(...) and the testing browser's bootstrapper has its |
i haven't tried any tests on embedded stuff. i'll try to reproduce this and make sure it doesn't affect the work on this PR. In the meantime, is Nancy.Test.csproj the name of your test project? i'm not sure if this is an issue, but my first guess would be to try changing the assembly name of your test project and make sure the name isn't causing Nancy to ignore your test assembly. |
Good suggestion; however my test assembly, containing Nancy tests, is actually *Application.Test -- so no references to Nancy. I'll keep digging; appreciate the response. |
i have working tests in my test project for this PR, so i'm not sure what could be wrong. Here's a gist of my test class in case an example might help point out a direction to pursue in debugging your issue. If you ping me in chat maybe i can help you out. |
Oh snap! 👊 The Mono build hates me 💔 😢 |
|
|
OK, @thecodejunkie & @grumpydev, i think this is ready for some review. Mind throwing some 👀 over this one? |
This fixes a bug discovered by Rex Whitten and mentioned in the mailing list: https://groups.google.com/d/msg/nancy-web-framework/9N4f6-Y4dNA/ZcGu35SBMoYJ
…w exceptions if there's only one view found
Rebased against master, sorry if that blows anybody's work away 😭 |
Apparently rebasing breaks travis? |
This closes NancyFx#732 and closes NancyFx#1332.
i added a home route and view to your example because some dumb guy was confused when he navigated to the host URL and saw a 404 monster. He also might have incorrectly assumed that @khellang screwed up 😝. |
AIGHT! We're good to go @thecodejunkie! |
Is there a reason why the AccountModule.cs contains the HomeModule and the HomeModule.cs contains the AccountModule? 😝 |
/// <summary> | ||
/// Initializes a new instance of the <see cref="EmbeddedViewLocationProvider"/> class. | ||
/// </summary> | ||
public EmbeddedViewLocationProvider() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we ditch this constructor and register the DefaultResourceReader
in Registrations
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally!
IF IT AIN'T BROKE DON'T FIX IT. Good catch, i must not have kept track of which file i was editing when i copied the account module into the home module. |
Hey @jugglingnutcase - have an issue serving static files as embedded resources (from a separate assembly) using the StaticContentsConventions along with Microsoft.Owin.Host.SystemWeb . IIS doesn't seem to like Nancy from OWIN. (example: http://salesapp.us/_Nancy ) I made a repo for a repro: http://goo.gl/FtqLmH ; everything works fine when self hosted on a cloud service: (http://sel2.us/_Nancy) . |
@TheFastCat i see you were able to post this issue on the mailing list. Fortunately for this PR, it looks like it's not related. |
@thecodejunkie Any chance of this getting into 0.22? |
At this point, i'm warring with this PR. Let me vomit out my thoughts for you 👅 Here's what i'm using in my own project that i want this PR for:
Here's what i want:
This PR meets my first want, but not the others, i think (unless i do some ugly hackery). Some options i'm considering for moving forward:
i feel obligated to point out that option 3 doesn't really exclude the other options. i'm willing to put this out as its own NuGet package and then move forward on my own. Any thoughts? |
I still want this very much, the embedded story is lacking a bit today. I don't really care whether it's part of the Nancy repo or not, t'll still be a separate NuGet package 😄 |
I want it as well but since it's been a few months on getting out the door I've started investigating Owin.StaticFiles to serve the same purpose. randompunter and pinpointtownes and tracher have been helpful with the transition. It looks like it will simplify my verbose Nancy StaticContentsConventions I currently have to define: ...but there is an issue that needs to be resolved first... https://katanaproject.codeplex.com/workitem/202 |
Haha! Remember - there's nothing stopping you from creating your own extension method 😄 |
@jugglingnutcase I started an OWIN middleware project for Cassette in case you haven't seen it. It could use some unit test love (it currently has none) but otherwise it seems to work well for my needs. |
@xt0rted i had that project in mind when i wrote that 😉 i should've put in a link... i'll be exploring that project soon 😄 |
@khellang i'm also OK with either. If i get a merge, then 🆒. If not, i'd like a thumbs down or a ping at some point (i'm not in a huge rush) so i can start moving this out to another repo. |
@TheFastCat Maybe you've already thought through this, but why aren't you just putting all your javascripts in a common folder and then adding the parent scripts directory? Wouldn't that work without all that code ceremony? Am i missing something? |
This reverts commit 6ccb39a. Conflicts: src/Nancy.Embedded.Tests/Unit/EmbeddedViewLocationProviderFixture.cs src/Nancy.Embedded.Tests/Unit/ResourceViewLocationProviderFixture.cs src/Nancy.Tests/Unit/ViewEngines/ResourceViewLocationProviderFixture.cs src/Nancy/ViewEngines/ResourceViewLocationProvider.cs
i'm planning on moving this stuff to my GitHub account and releasing it through NuGet. i'll let you know when it's up 😄 |
This code is branching off the work done in NancyFx/Nancy and the work in NancyFx/Nancy#1331.
Okey-dokey, it's moved. i'll publish it up on NuGet soon. Please let me know if there's any licensing stuff that i need to take care of. |
This PR seeks to put embedded content on the SDHP by fixing a remaining issue and closing out #732.
Questions i have
Should i move everything related to embedded views out of core Nancy and into Nancy.Embedded?When wiring up embedded views for Nancy, i followed this post by Simon Cropp. It was pretty simple, but according to Create Nuget for working with embedded stuff #732 it sounds like @grumpydev had some ideas on how to improve wiring up embedded views. Is there a better way to wire up embedded views?Done
AddDirectory
for embedded static content, similar to the extension method on the defaultStaticContentConventions
ApplicationRegistration
RootNamespaces
added and only one embedded view to serve.