1

I chose MongoDB and .Net Core 2.3 as technologies for a new webapp and was wondering what guidelines should I use. As i'm coming from Relational DB world, I watched like 5 MongoDB/C# tutorials so far but i'm still wondering:

  • Is there a way to implement in a "clean" way Data Access Layer ? (like making a new Project for example)
  • Is repository pattern really useful or overkill ? (I may change DB source if MongoDB is too tricky to maintain and switch back to RDB but MongoDB already won half of my heart so far)
  • How to implement "n-n relationships" such as a list of object in an object ? If i'm doing an update on one of the object of the list, am I going to update all same instances of it everywhere ? Sorry for the heresy.

There it is. Thanks in advance for every answer, every link, every vote.

I already started to use MongoDB.Bson lib and watched Tim Corey's tutorial (https://www.youtube.com/watch?v=69WBy4MHYUw).

3
  • The most basic guideline is, If you're familiar with relational DB's just stick with them. What's the point in switching over if they're both just as effective?
    – Train
    Oct 3, 2019 at 20:59
  • 1
    you might find my convenience library MongoDB.Entities interesting. it makes a few things easier and adds a couple of features to the driver. Oct 4, 2019 at 5:57
  • Interesting library @RyanGunner but what i'm looking for is common patterns and guidelines. So many articles, so little ressources about how to start a maintainable project but thanks anyway !
    – AceKing
    Oct 4, 2019 at 6:23

1 Answer 1

1

i created a github repo with a starter template that you might find useful. it's what i typically do for medium to large scale web apps that requires keeping things simple for maintainability. the code should be easy to follow if you use visual studio. if you need any help with any part, create an issue in the repo and i'll try my best to answer.

here are a few highlights of the template:

3 Layer Architecture

  • a single layer only references the layer immediately below it.
  • a layer has no idea about what's consuming it.

Api Layer

  • strongly typed app settings
  • JWT token authentication
  • policy based authorization
  • custom middleware for putting site offline (maintenance mode)

Business Layer

  • input validation with fluentvalidation rules
  • account creation, email validation, login
  • salted hash password storage and verification with bcrypt
  • email queue with background service for sending emails with smtp
  • image uploading

Data Layer

  • data is stored in mongodb
  • data is modified & retrieved via manager classes

Integration Tests

  • uses mstest framework
  • uses fluentassertions
  • tests business logic via controller actions

it's not perfect but it seems to work for my team without much trouble. if anybody sees anything wrong or has any feedback, suggestions for improvement, please don't hesitate to comment.

thanks!

3
  • 1
    Your answer is a bless, I'll make some pull request if I can bring anything relevant ! Thanks for project !
    – AceKing
    Oct 6, 2019 at 1:46
  • @AceKing you're most welcome. i've done a bit or re-organizing in the project. pull from master branch and have a look. as for your question regarding relationships, have a look at the wiki pages of my library here and here. as for the repository pattern, i'm not really a fan. the manager classes serves the purpose of isolating the data/query logic to the data layer. managers are basically a data api which remains static even when swapping db engines. Oct 6, 2019 at 10:56
  • 1
    btw @AceKing i think you meant .net core 2.2 because there's no 2.3. after 2.2, they went straight to 3.0. see if you can correct the post. cheers! Oct 6, 2019 at 11:00

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.