I'm setuping a C# Asp.Net Core Api that will grow quite a bit in the future. So I'm trying to respect the Clean Code architecture, with my domain in the center without any dependences and everything around:
public abstract class Entity
{
public Guid Id { get; set; }
}
I'm currently implementing the repositories. My issue is that for mongoDb, it seems mandatory to either provide the [BsonId] attribute, either use the BsonId in my entities. But that implies adding a mongoDb reference in my entity project, which I'm not a big fan.
public interface IRepository<TDocument> where TDocument : Entity
{
IQueryable<TDocument> AsQueryable();
IEnumerable<TDocument> FilterBy(
Expression<Func<TDocument, bool>> filterExpression);
IEnumerable<TProjected> FilterBy<TProjected>(
Expression<Func<TDocument, bool>> filterExpression,
Expression<Func<TDocument, TProjected>> projectionExpression);
Task<TDocument> FindOne(Expression<Func<TDocument, bool>> filterExpression);
Task<TDocument> FindById(Guid id);
Task InsertOne(TDocument document);
Task InsertMany(ICollection<TDocument> documents);
Task ReplaceOne(TDocument document);
Task DeleteOne(Expression<Func<TDocument, bool>> filterExpression);
Task DeleteById(Guid id);
Task DeleteMany(Expression<Func<TDocument, bool>> filterExpression);
}
In the example I found on Clean Architecture, they are mostly using entity framework, which doesn't require absolutely attributes to work.
I could imagine doing another class and using AutoMapper to map between each other, but that seems cumbersome, since I always want to persist everything that are in my business object, and that could lead to some errors.
Isn't there a way to indicate per collection(or even globally) what is the Id in the repository or when saving ?