I'm working on a new project and I had to design some REST Services with ASP MVC WebApi.
I would like to show you my app architecture and learn from more experienced architects what I have potentially done wrong (I'm not an experienced architect). Can you please let me know your thoughts and recommendations?
Self-identifiable and self-validatable entities
All my entities inherit from BaseEntity<T>
which is a generic because is implementing IIdentifiable<T>
.I created IIdentifiable<T>
in order to be able to have a unique way of getting the id of an entity. The entity Ids don't always use the same data type that's why the interface is generic.
BaseEntity<T>
base entity also implements IValidatable
which provides with a unique way of validating an entity.
Data access layer
All my repositories implement IRepository<T, IdT>
which is used to implement the basics default CRUD operations. T
is the entity type and IdT is the type of the entity ID.
The repositories don't implement directly IRepository<T, IdT>
, for example, TermRepository
implements ITermRepository
and ITermRepository
implements IRepository<Term, int>
. I did it that way so I can add the Term
non-standard CRUD operations to the ITermRepository
interface.
Service layer
I have created a generic abstract class BaseHttpController<T, IdT>
which implements IService<T, IdT>
just like in the data access layer T
is the type of an entity an IdT
is the type of the entity's ID.
I don't have to implement the default REST operations because they are implemented in the BaseHttpController<T, IdT>
class. BaseHttpController<T, IdT>
has access to IRepository<T, IdT>
If I need to implement something non-standard I can do it in the in the controller. From a controller (e.g. TermController
) I can access its repository (e.g. TTermRepository
).
All the REST services return a generic Response<T>
object to wrap the entities and errors.
Note: I'm using IoC and each layer is in an independent DLL.
Thanks!