How do I use models from Project A in Project B?
Lets say I have a models folder with a few models in it inside of Project A and I've created another project under the same
.sln
called Project B. I instead of having to create duplicate models between both projects, I want to use the models with Project A's models folder inside of Project B. I tried
but I get a resolve error basically saying it can't find it, but the folder structure is
. Thanks in advance.16 Replies
Add a reference to the project
Then import the namespace with
using
ok I won't go that route then. If I reference each project to each other, it creates a circle problem. I'll figure that part out later
You can pull the common elements to another,
Shared
projectthere isn't a shared project unfortunately. thanks though ❤️
But you can make a shared library and ref it from A and B.
oh ok so like have multiple projects then
type thing yea?
yeah, sorta
you'd have one (or more, but eh) "runner" projects - a console app, avalonia, whatever. some kind of executable project type
and several class library projects, separated by whatever makes sense for you
so what would the file structure
something like this would be very common
ok cool. So like what would each section be about? Example: MyProj I know is the root of the project. Inside of
src/
there's Common, Desktop, and Infrastructure. I presume that Desktop is where I would do all of my normal coding and such with the Views and ViewModels, but I'm not sure what would go in Common or Infrastructure. I'm using MongoDB local host db for testing and building and then I'll be using it for production, but with a different cluster, so like would my Database calls of GET, PUT, UPDATE, DELETE in the Infrastructure part?Anything related to the database would go in infrastructure
While common would be the stuff shared between other projects, usually a bunch of classes or interfaces that are used everywhere
But if you don't need multiple projects, don't use it
A classic example would be if you want to have a desktop client and a console client, or of you also plan to make a server
Then you must have multiple projects, and a shared library between them would solve a lot of issues
so to make sure I understand this part correctly. I should manually create the root folder along with the git ignore and the editor config and a src folder and then open that in rider, and inside of the src folder, I would create new projects as shown above?
ok so the first project that I'm applying this methodology to is a Diary application. It'll be using an online database and it'll have a console version as well. The desktop app will be avalonia if that makes a difference
ok so I've got the project setup like you showed. How do I share the projects? add a new reference in the dependencies?
yea that's it. Ok so would I reference Infrastructure and Common inside Desktop? Or what's the combo?
and would I create another project for the console application too and then build the avalonia app inside the Desktop folder?
nvm lol honestly. This is a bit like wow haha but I'm going to build them as separate applications, and they'll reference the same database and be two separate applications with separate downloads
Yeah, you'd so exactly as the tree but just add a fourth one called Cli or Console or whatever.
And you would publish it as it's own executable
ohhhhh ok. so create them like above, but distribute as separate executables. idk why I didn't think of that lmao ty! ok so with referencing the other projects in the main projects would I reference them by referencing Infrastructure and Common in both Desktop and CLI?
so I could put all of my models/helper classes/etc that would be used between both Desktop and CLI in the Common project and I put all database stuff in the Infrastructure project since Common and Infrastructure are shared between Desktop and CLI and then I'd reference Infrastructure and Common in both the Desktop and CLI applications
Yep
bet. sweet. gonna give that a go now. Thanks!