I have been working on an MEF/Servicestack based framework for an SaaS product. I am compiling razor views into external modules that are loaded during runtime with MEF. I am struggling trying to embed javascript resources into the dlls and then referencing them successfully when the view is loaded. Has anyone had any success with this?
The section on Embedded Resources in Virtual File System wiki explains the Embedded Resources support in more detail where you just need to ensure the Assembly that contains your embedded resources is defined in either the Config.EmbeddedResourceSources
Assembly list or Config.EmbeddedResourceBaseTypes
types list, e.g:
SetConfig(new HostConfig {
EmbeddedResourceSources = { typeof(TypeInDllWithEmbeddedResources).Assembly },
EmbeddedResourceBaseTypes = { typeof(TypeInDllWithEmbeddedResources) }
});
However typically no configuration is needed as the top-level Assembly where your AppHost
is defined is automatically pre-registered and as it's also typically the same Assembly where your Website resources are maintained, any embedded resources in that Assembly are automatically available. E.g. if you have an embedded resource in your project at /dir/file.js
it would be available from the same path where ServiceStack is mounted, e.g http://localhost:1337/dir/file.js
.
You just need to make the file an Embedded Resource by setting the Build Action in the File property panel in VS.NET to Embedded Resource so that it gets compiled as an embedded resource in your Website .dll.