C
C#•2mo ago
Dante

Question about best practices for project org

Im a beginner in C#, but I do have extensive experience in JS (NodeJS/React). That means I can make things work by just googling answers, but there's one thing thats been confusing the hell out of me: Project structure & naming conventions I'm seeing different approaches and Im unsure which would be the best. DTO folders? Entities Folders? Models Folders? Helpers? Services? Can anyone recommend a good project structure that you have seen widely used ? Id need something that says "in the models folder you add your API models" for example - just so I get an idea. I know the question might be a bit far fetched, but Im hoping to get any kind of advice at this point. Unfortunately this is not something I am able to learn on my own and Im currently only working on personal projects on C#. Appreciate it. EDIT: Articles, tutorials or whatever you deem necessary is also welcome.
11 Replies
hutoanhill
hutoanhill•2mo ago
dont do what i do and throw all you classes into a single 2k line file
Dante
Dante•2mo ago
haha, Im trying to go with 1 class/1 file approach as much as possible. Im probably gonna have more classes in the same file at some point, but for now Im good 😄 thanks
hutoanhill
hutoanhill•2mo ago
yea i am a very special kind of weird.
Becquerel
Becquerel•2mo ago
people do a lot of different things i personally think vertical slices are a decent strategy all your code for user signups live in a 'Signups' directory... the model, the endpoint, the services, etc this means code that is related to each other semantically is also close to it physically
Dante
Dante•2mo ago
hmmm ok yeah, that sounds like it makes sense for big projects
Becquerel
Becquerel•2mo ago
if i'm looking at UserModel, it isn't really useful for me if a PostModel is next to it in the filesystem just because they're both models
Dante
Dante•2mo ago
ok so its more like feature based, what do you usually have in your ...lets say BlogPost folder ? Folders for Models, Controllers, Services ? also what about those services or utilities that are used in all features, like for example the DB context (unless you're using multiple db contexts, something Im still trying to wrap my head around) ? Do you have generic folders in the root of the project for those I'm assuming?
Becquerel
Becquerel•2mo ago
the dbcontext specifically usually lives in its own project along with the database models (they don't get used in the rest of the solution) but yeah i typically have an 'Infrastructure' folder where i put odds and ends like, that's where i put the class where i register everything in DI or have stuff relating to logging, open telemetry, whatever
Dante
Dante•2mo ago
sounds pretty organized, I like the sound of it, thanks for the tip 🙂
Becquerel
Becquerel•2mo ago
no problem 🙂
Mayor McCheese
Mayor McCheese•2mo ago
The ultimate rule is be consistent
Want results from more Discord servers?
Add your server