Document database like MongoDb lets you use your business objects directly by attributes attributes to fields/properties as shown below.
public class Book
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
[BsonElement("Name")]
public string BookName { get; set; }
public decimal Price { get; set; }
public string Category { get; set; }
public string Author { get; set; }
}
Here [BsonId] attribute specifies a MongoDb primary key. Even though it can be though as a flexibility, it is very specific to MongoDb. Now the Book class is becoming depending on MongoDb libraries as well. As different projects (projects in .net, packages in Java etc.) use the above Book class, they also become dependent on MongoDb libraries and that in turn breaks the loose coupling between projects.
Given the background, is it worth creating an identical mapping class just to avoid the dependencies (or use tools like Automapper https://automapper.org or http://dozer.sourceforge.net/ for Java)?
Is it worth the extra plumbing vs violating the principles of loose coupling of sub-systems and single responsibility principle?
Aucun commentaire:
Enregistrer un commentaire