I'm trying to create a nice a Solution structure for a new DDD project. I Created a "Core" project, where I added the Entities, ValueObjects and the repositories Interfaces then I added an "Infrastructure" project that contains the implementation of the previous IRepository.
Now, since my db will be MongoDb I need to add the attributes like "[BsonDateTimeOptions]" in some of the fields of the Entities, this will require to add a reference to the MongoDb driver package in the core project.
Since the core project should not contains any reference to MongoDb, should only contains business logic and it should be reusable in any other project (mobile - Xamarin) what should be the best practice in this situation?
What I'm able to think is:
This approach has a problem, that I will have a copy of the entity, the model, which only has the MongoDb attributes, and when adding some fields to an entity, I will have to modify the model too. Is this the correct approach?
Everything started from this solution structure.
Instead of using attributes in your domain classes, write configuration code in the Infrastructure layer.
This seems to always be an option with MongoDB.NET, e.g.
BsonClassMap.RegisterClassMap<MyClass>(cm =>
{
cm.AutoMap();
cm.MapMember(c => c.DateOfBirth).SetSerializer(new DateTimeSerializer(dateOnly: true));
}
instead of
[BsonDateTimeOptions(DateOnly = true)]
public DateTime DateOfBirth { get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With