I am starting a new project in which the idea is to organize the project file/folder structure in to different modules (.csproj) and finally once deployed these modules would be loaded to one AppHost of MainModule (these sub modules would act as plugins).
However, for better physical file management (SVN/VCS) and effective organization of my project files these modules would be maintained as separate projects in SVN too. Thought is to have views, assets etc. specific to each module in its own module directory scope. (Refer screenshot).
Main Module
SubModuleOne
Views
ModuleOneDefault.cshtml
SubModuleTwo
Views
ModuleTwoDefault.cshtml
Views
Shared
_Layout.cshtml
Hello.cshtml
Module specific files would be copied as post build action into root project path rather than /Views directly (if copied then it messes up with Main module's Views folder).
Problem is with how ServiceStack loads and handles Razor views from /Views folder and anything outside is considered to be content pages. More about this, explained here...!
With VirtualFileSystem in place I was thinking aloud to maintain module specific views in respective "/ModuleOne/Views/" folder but outside the root "/Views". Somehow, this doesn't seem to work, trying to seek help on how this could be achieved or handled appropriately.
PS: Am aware that anything outside Views folder is content pages, however the idea is still to maintain as Views folder but in different hierarchy - Hoping that ServiceStack Razor feature anyway handles nested (DEEP) structure well but within root /Views folder and not from the entire Project Root folder i.e. "/".
Question is, can this be achieved as is by default without any heavy lifting? or Should I be having custom VirtualPathProvider implementation etc.?
Opinion and thoughts are greatly appreciated!
Thanks!
All Razor Views must be in the /Views folder but otherwise they can be any hierarchy as any levels of nesting doesn't affect how they're resolved, they just need to be uniquely named, e.g:
/Views
/SubModuleOne
ModuleOneDefault.cshtml
/SubModuleTwo
ModuleTwoDefault.cshtml
/Shared
_Layout.cshtml
Related
Context:
I have an express web server which I'm using as a sort of 'template' to create solutions for customers. The needs and use-cases of customers in the industry I work in are all somewhat similar, and therefore most static resources (images, es6 modules etc.) are shared between them. These are all in the root /static/ folder. There are cases where the customers needs necessitate individualized scripts and resources in which case I place them under their respective solution folder, e.g. solutions/solutionA/static/def.js for customer A. In server.js, the express launcher script, I set two static directories through middleware. /static (for shared stuff), and /solutions/ACTIVE SOLUTION/static (for solution specific stuff), where ACTIVE SOLUTION is a constant string specified at the top of the file.
node_modules/
static/
abc.js
solutions/
solutionA/
static/
def.ts
solutionB/
static/
ghi.ts
solutionC/
static/
server.ts
tsconfig.json
Problem:
My problem lies with typescript complaining about es6 import statements. From within say solutions/solutionA/static/def.ts, I cannot do
import abc from "./abc.js"
even though this is correct in-browser, as I have set the root /static as a static folder.
Is there any way I can indicate to typescript via tsconfig.json or other means, that I would like it to also search in a particular directory for said files (in this case, the root /static?). I do not want the resulting js files to have their import paths changed, as /abc.js will indeed be valid due to the express middleware.
Current situation:
As the imports are correct when loaded in browser, my solution is currently "working". The issue lies in the fact both visual studio code and tsc rightfully complain of the incorrect import path. This is a fairly recent refactoring, the merging of like solutions to stop splintering. It seemed like a good idea, only now my entire project is littered with errors.... Other people are going to be working on my solution eventually, and I don't want to give them something with copious amounts of worrying warnings.
Most Node examples and tutorials suggest setting up directories for Model, Views and Controllers and an "app.js" as a main file of the app. It seems a bit messy, since the app.js insn't really any of the MVC trio. It is actually quite a good candidate to be a controller, which works with the model and view modules.
So: Is it rule or convention breaker to go ahead with a M+V+app.js scenario, in case not more then one controller module is needed?
The ideal file structure for your node application is the structure that best fits your needs. There is no absolute rule about how to structure your app.
MVC is a generic template to structure your application, which you are free to use, or not.
By convention, the root file of your node application is an app.js or an index.js file.
If your application logic is simple enough that you to do not need to put your controllers files in a separate directory, you can stay with your app.js file alone.
That will not break the MVC paradigm as MVC is a pattern, not a directory structure.
Node/NPM newbie with a front-end dev question. I understand one of the strengths of an NPM-type module is that its dependencies get installed within itself, in node_modules. Modules always have the code that they need, and outside libs don't conflict.
That said, seems like this would result in the client downloading the same lib+ver (say, jquery v.X) multiple times. What's the technique for specifying that a module needs a dependency but that it shouldn't package that code if the dependency is already available on the site/page? Does said technique involve parent modules that make the shared lib+ver available?
Or, should various front-end modules just re-download the same lib+ver that other modules on the page might have already downloaded?
The client will only grab files from that folder that are needed, so if it's linked in HTML once the client will only grab it once. NPM handles dependency duplicates automatically.
Having said that, normally you will want to only serve a static folder to the client without revealing your entire server structure. This can be achieved using:
app.use(express.static('server/public')
where 'server/public' is the directory relative to the server.js file that you want to serve. In this case, 'public' contains all my linked view files, stylesheets, JS files, etc. that are linked from the HTML pages. You don't need to move that module's dependencies there as well.
The downside to this is that you'd have to manually move dependencies into the public folder (I make a 'vendor' directory usually) and link from there. It's more work but it's much more efficient and safer in the long run.
NOTE: when using a static folder to serve files, your HTML links will be served from a relative path to that folder.
I have an existing solution (multiple projects, one MVC web project) that I'm trying to wrap into an Orchard module.
All documentation says that the web csproj should be at the root under my module directory (eg Modules/MyModule/MyWeb.csproj).
However, I have an existing solution structure where the sln file sits at the top level and each csproj file (and project content) sits in its own directory (the standard solution structure when you build a multi-project app in Visual Studio).
Is there a way I can tell my Module.txt file that the Orchard Module csproj is under MyModule/MyWeb/MyWeb.csproj? I'd prefer to not restructure the whole solution.
Thank you.
Note: As a point of clarification, it is not ~/Modules/MyModule/MyWeb.csproj but ~/Modules/MyModule/MyModule.csproj. The Folder name of the Module must match the file name of the project (before .csproj). This is enforced by the Dynamic Extension Loader, which requires ~/Module/{ModuleId}/{ModuleId}.csproj. (A similar approach is required for themes.)
The only potential way to do this is to write a custom module that follows the above that contains a custom loader. Within your module, create your own implementation of IExtensionLoader, and register it with Autofac. However, I don't know if it would work; I've never tried.
You will probably have an easier time reorganizing your solution.
I am using bower packaging system to fetch files to local project however breaking conventions these files are useless on their own. They need to be injected in the proper location in the MVC framework I'm using so whatever bower fetches I need to essentially do a post action and copy the directory structure / files from components/myexample/ to application/
remote bower package:
controllers
mycontroller.php
models
mymodel.php
view
layout
myview.php
composer.json
local project:
composer.json
components
myexample
controllers
mycontroller.php
models
mymodel.php
view
layout
myview.php
application
controllers
models
view
I was thinking of upon retrieving the directory structure and files to zip it all and then do an extract to the right directory. I need the solution to be cross platform compatible. How would you do it and better yet how else would you implement this?