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
- Host: GitHub
- URL: https://github.com/dimitrietataru/catnip-domain
- Owner: dimitrietataru
- License: mit
- Created: 2024-01-05T12:49:43.000Z (over 2 years ago)
- Default Branch: ace
- Last Pushed: 2024-11-26T00:10:56.000Z (over 1 year ago)
- Last Synced: 2025-04-10T00:05:25.371Z (about 1 year ago)
- Topics: abstractions, clean-architecture, csharp, domain, dot-net
- Language: C#
- Homepage:
- Size: 50.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Clean Architecture Template - Never-ending Improvement Process
[](https://github.com/dimitrietataru/catnip-domain/actions/workflows/build.yml)
[](https://github.com/dimitrietataru/catnip-domain/actions/workflows/release.yml)
[](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).