简体   繁体   中英

Nancy - embedded views from other assembly

I have created 2 projects:

  1. Class library with file Views\\other.html set as embedded resource.

  2. Console app with Nancy self-hosting set up, bootstrapper and nancy module that simply responds to a GET by returning a view named "other.html" - the one defined in the other assembly.

Bootstrapper config:

protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{  
    base.ConfigureApplicationContainer(container);
    ResourceViewLocationProvider.RootNamespaces.Add(GetType().Assembly, "ConsoleApplication1.Views"); // (1)
    ResourceViewLocationProvider.RootNamespaces.Add(typeof(Class1).Assembly, "ClassLibrary1.Views");
}

protected override NancyInternalConfiguration InternalConfiguration
{
    get { return NancyInternalConfiguration.WithOverrides(OnConfigurationBuilder); }
}

private void OnConfigurationBuilder(NancyInternalConfiguration x)
{
    x.ViewLocationProvider = typeof(ResourceViewLocationProvider);
}

Application starts properly with this configuration but it fails to return the "other.html" which is defined as embedded resource of the other library.

It works ok when I return a view that is embedded in the main console app.

When I remove the line marked as (1) then app fails to start with the following error:

Unable to resolve type: Nancy.ViewEngines.ViewEngineApplicationStartup
Only one view was found in assembly ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, but no rootnamespace had been registered.

What am I missing here?

Problem solved at: https://groups.google.com/forum/#!topic/nancy-web-framework/9N4f6-Y4dNA

Looks like currently available Nuget package doesn't contain this fix !!!

I decompiled 0.22 nuget package and for me this change isn't there. It is on github.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM