Skip to content

dimitrietataru/catnip-domain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clean Architecture Template - Never-ending Improvement Process

build release NuGet

Domain Abstractions

IModel

Introducing the IModel type.

interface IModel
{
}

At Service and Repository layer, the following actions can be performed:

  • Queries
    • GetAll()
    • Count()
  • Commands
    • Create(TModel)
    • Update(TModel)
    • Delete(TModel)
IModel abstractions

Definition

interface IModel
{
}

abstract class Model : IEquatable<Model>, IModel
{
    public override bool Equals(object? obj) { .. }
    public override int GetHashCode() { .. }

    public abstract bool Equals(Model? other);
    protected abstract int DetermineHashCode();
}

Service

interface IQueryService<TModel>
    where TModel : IModel
{
    Task<IEnumerable<TModel>> GetAllAsync(CancellationToken cancellation);
    Task<int> CountAsync(CancellationToken cancellation);
}

interface ICommandService<TModel>
    where TModel : IModel
{
    Task CreateAsync(TModel model, CancellationToken cancellation);
    Task UpdateAsync(TModel model, CancellationToken cancellation);
    Task DeleteAsync(TModel model, CancellationToken cancellation);
}

interface ICrudService<TModel> : IQueryService<TModel>, ICommandService<TModel>
    where TModel : IModel
{
}

Repository

interface IQueryRepository<TModel>
    where TModel : IModel
{
    Task<IEnumerable<TModel>> GetAllAsync(CancellationToken cancellation);
    Task<int> CountAsync(CancellationToken cancellation);
}

interface ICommandRepository<TModel>
    where TModel : IModel
{
    Task CreateAsync(TModel model, CancellationToken cancellation);
    Task UpdateAsync(TModel model, CancellationToken cancellation);
    Task DeleteAsync(TModel model, CancellationToken cancellation);
}

interface ICrudRepository<TModel> : IQueryRepository<TModel>, ICommandRepository<TModel>
    where TModel : IModel
{
}

IModel<TId>

Introducing the IModel<TId> type

interface IModel<TId> : IModel
    where TId : IEquatable<TId>
{
    TId Id { get; }
}

At Service and Repository layer, the previous actions are extended and the following extra actions can be performed:

  • Queries
    • GetById(TId)
    • Exists(TId)
  • Commands
    • Create(TModel)
    • Update(TId, TModel)
    • Delete(TId)
IModel< TId > abstractions

Definition

interface IModel<TId> : IModel
    where TId : IEquatable<TId>
{
    TId Id { get; }
}

abstract class Model<TId> : Model, IModel<TId>
    where TId : IEquatable<TId>
{
    public virtual TId Id { get; set; }

    public override bool Equals(Model? other) { .. }
    protected override int DetermineHashCode() { .. }
}

Service

interface IQueryService<TModel, TId> : IQueryService<TModel>
    where TModel : IModel<TId>
    where TId : IEquatable<TId>
{
    Task<TModel> GetByIdAsync(TId id, CancellationToken cancellation);
    Task<bool> ExistsAsync(TId id, CancellationToken cancellation);
}

interface ICommandService<TModel, TId>
    where TModel : IModel<TId>
    where TId : IEquatable<TId>
{
    Task<TModel> CreateAsync(TModel model, CancellationToken cancellation);
    Task UpdateAsync(TId id, TModel model, CancellationToken cancellation);
    Task DeleteAsync(TId id, CancellationToken cancellation);
}

interface ICrudService<TModel, TId> : IQueryService<TModel, TId>, ICommandService<TModel, TId>
    where TModel : IModel<TId>
    where TId : IEquatable<TId>
{
}

Repository

interface IQueryRepository<TModel, TId> : IQueryRepository<TModel>
    where TModel : IModel<TId>
    where TId : IEquatable<TId>
{
    Task<TModel> GetByIdAsync(TId id, CancellationToken cancellation);
    Task<bool> ExistsAsync(TId id, CancellationToken cancellation);
}

interface ICommandRepository<TModel, TId> : ICommandRepository<TModel>
    where TModel : IModel<TId>
    where TId : IEquatable<TId>
{
    Task<TModel> CreateAsync(TModel model, CancellationToken cancellation);
    Task UpdateAsync(TId id, TModel model, CancellationToken cancellation);
    Task DeleteAsync(TId id, CancellationToken cancellation);
}

interface ICrudRepository<TModel, TId> : IQueryRepository<TModel, TId>, ICommandRepository<TModel, TId>
    where TModel : IModel<TId>
    where TId : IEquatable<TId>
{
}

Related projects

License

CatNip.Domain is Copyright © 2023 Dimitrie Tataru and other contributors under the MIT license.