An open API service indexing awesome lists of open source software.

https://github.com/dimitrietataru/catnip-domain

CatNip - Domain Abstractions
https://github.com/dimitrietataru/catnip-domain

abstractions clean-architecture csharp domain dot-net

Last synced: 5 months ago
JSON representation

CatNip - Domain Abstractions

Awesome Lists containing this project

README

          

## Clean Architecture Template - Never-ending Improvement Process

[![build](https://github.com/dimitrietataru/catnip-domain/actions/workflows/build.yml/badge.svg)](https://github.com/dimitrietataru/catnip-domain/actions/workflows/build.yml)
[![release](https://github.com/dimitrietataru/catnip-domain/actions/workflows/release.yml/badge.svg)](https://github.com/dimitrietataru/catnip-domain/actions/workflows/release.yml)
[![NuGet](https://img.shields.io/nuget/v/CatNip.Domain)](https://www.nuget.org/packages/CatNip.Domain)

# Domain Abstractions

## IModel

Introducing the **IModel** type.

``` csharp
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
``` csharp
interface IModel
{
}

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

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

### Service
``` csharp
interface IQueryService
where TModel : IModel
{
Task> GetAllAsync(CancellationToken cancellation);
Task CountAsync(CancellationToken cancellation);
}

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

interface ICrudService : IQueryService, ICommandService
where TModel : IModel
{
}
```

### Repository
``` csharp
interface IQueryRepository
where TModel : IModel
{
Task> GetAllAsync(CancellationToken cancellation);
Task CountAsync(CancellationToken cancellation);
}

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

interface ICrudRepository : IQueryRepository, ICommandRepository
where TModel : IModel
{
}
```

## IModel\

Introducing the **IModel\** type

``` csharp
interface IModel : IModel
where TId : IEquatable
{
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
``` csharp
interface IModel : IModel
where TId : IEquatable
{
TId Id { get; }
}

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

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

### Service
``` csharp
interface IQueryService : IQueryService
where TModel : IModel
where TId : IEquatable
{
Task GetByIdAsync(TId id, CancellationToken cancellation);
Task ExistsAsync(TId id, CancellationToken cancellation);
}

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

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

### Repository
``` csharp
interface IQueryRepository : IQueryRepository
where TModel : IModel
where TId : IEquatable
{
Task GetByIdAsync(TId id, CancellationToken cancellation);
Task ExistsAsync(TId id, CancellationToken cancellation);
}

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

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

### Related projects
* [catnip-application](https://github.com/dimitrietataru/catnip-application)
* [catnip-infrastructure](https://github.com/dimitrietataru/catnip-infrastructure)
* [catnip-presentation](https://github.com/dimitrietataru/catnip-presentation)
* [csharp-coding-standards](https://github.com/dimitrietataru/csharp-coding-standards)

### License
CatNip.Domain is Copyright © 2023 [Dimitrie Tataru](https://github.com/dimitrietataru) and other contributors under the [MIT license](https://github.com/dimitrietataru/catnip-domain/blob/ace/LICENSE).