C#C
C#2y ago
151 replies
electronic heartbreak.

✅ Expandability of the ASP.NET WEB API - Mongo tutorial code

Hello there,

I am currently following this tutorial: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mongo-app?view=aspnetcore-8.0&tabs=visual-studio

This tutorial explores the integration of mongo and c#. What in this tutorial is done is that they set collection, database and connection in the env-like file. This means that when you have multiple collections you need to add them here and expend all the setting classes.

Another issue I see with this is that https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mongo-app?view=aspnetcore-8.0&tabs=visual-studio#add-a-crud-operations-service is not maintainable in the long run, becuase of this line:
_booksCollection = mongoDatabase.GetCollection<Book>(
            bookStoreDatabaseSettings.Value.BooksCollectionName);


Would an EF-like approach be more suitable? So you have a MongoDBContext class that holds the collections and DI this Context class into the Service classes?
This tutorial demonstrates how to create an ASP.NET Core web API using a MongoDB NoSQL database.
Create a web API with ASP.NET Core and MongoDB
Was this page helpful?