Core Libraries
The Core Libraries project is a solution to store common libraries and utilities that are used by other projects. It includes functionality for shared configuration, persistence, observability, and other common tasks.
This library assumes the separation of a project in three layers:
- Business Layer: Contains the business logic of the project, like commands, events, queries, and other domain objects, as well as command handlers and validators, workflows, data access interfaces, and other services.
- Data Layer: Contains the data access logic of the project, like repositories, data access objects, and other data access services. It implements data-access interfaces defined in the Business Layer.
- Presentation Layer: Contains the presentation logic of the project, like controllers, views, and other presentation services. It interacts with the Business Layer using a mediator pattern.
Also, a preamble library is implemented, with general utilities like extensions to the .NET Core framework, logging, and other common tasks.
For each layer, a Testing project is included to make easier the creation of UnitTests and integration tests in each service’s project.
Preamble
The preamble library includes general utilities like extensions to the .NET Core framework, logging, and other common tasks.
Preamble Testing
Preamble Mappings
This class provides some utility methods to help test mapping functions.
It is assumed the use of
Riok.Mapperlylibrary to assist in mapping objects.
As it is recommended to avoid the automatic generation of mapping functions, you can use the following utility methods to check that all mapping functions are not private.
To test that all mapping functions are public, you can use the following Unit-Test code (using xUnit):
[Theory] [ClassData(typeof(MapperFollowsConventionData))] public void MapperFollowsConvention(MethodInfo method) { Assert.False( method.IsPrivate, $"{method.DeclaringType!.FullName}.{method.Name} should not be private.");
Assert.StartsWith("MapTo", method.Name, StringComparison.Ordinal); }
public class MapperFollowsConventionData : TheoryData<MethodInfo> { public MapperFollowsConventionData() { TdpCoreRestApis.Assembly .GetMapperMethods() // <- Get all mapping methods in the assembly .ForEach(Add); // Using `ForEach` in this testing context is ok. DO NOT USE IT in production code. } }Business Layer
Business Models
Business Paging
PagingQueryPagingQueryResultPagingQueryResultOf<TItem>
Business Sorting
SortingField<TEnum>SortingFieldDirection
Business Filtering
Business Field filters
| Done | Filter | String | Single | Equality | Comparison | Nullable |
|---|---|---|---|---|---|---|
| ✅ | BooleanFilter | ❌ | ✅ | ❌ | ❌ | ✅ |
| ☑️ | CollectionFilter | ❌ | ❌ | ❌ | ❔ [2] | ❌ |
| ✅ | DateTimeFilter | ❌ | ❌ | ✅ | ✅ | ✅ |
| ✅ | DateOnlyFilter | ❌ | ❌ | ✅ | ✅ | ✅ |
| ☑️ | DoubleFilter | ❌ | ❌ | ❌ | ✅ | ✅ |
| ✅ | EntityFilter | ❌ | ❌ | ✅[1] | ❌ | ✅ |
| ✅ | EnumFilter | ❌ | ❌ | ✅ | ❌ | ✅ |
| ☑️ | FeatureFilter [3] | ❔ | ❔ | ❔ | ❔ | ❔ |
| ✅ | Int32Filter | ❌ | ❌ | ✅ | ✅ | ✅ |
| ✅ | Int64Filter | ❌ | ❌ | ✅ | ✅ | ✅ |
| ✅ | StringFilter | ✅ | ❌ | ✅ | ❌ | ✅ |
| ✅ | TimeOnlyFilter | ❌ | ❌ | ✅ | ✅ | ✅ |
| ✅ | TimeSpanFilter | ❌ | ❌ | ✅ | ✅ | ✅ |
Legend:
- ✅: Supported
- ❌: Not supported
- ☑️: Not implemented yet
- [1]: The equality comparison is based on the entity’s Id.
- [2]: Integer comparison against the collection’s length.
- [3]: Feature flags are not yet implemented or well designed.
Business Operations
Business String related
String value filters allow for multiple values indicating that the field must be ANY of those values.
-
ContainsFilter: Represents a filter for a string field that contains a specific value. -
StartsWithFilter: Represents a filter for a string field that starts with a specific value. -
EndsWithFilter: Represents a filter for a string field that ends with a specific value. -
NotContainsFilter: Represents a filter for a string field that does not contain a specific value. -
NotStartsWithFilter: Represents a filter for a string field that does not start with a specific value. -
NotEndsWithFilter: Represents a filter for a string field that does not end with a specific value.
Business Single Equality related
Single value filters allow for a single value indicating that the field must be equal to that value.
-
EqualsToSingleFilter<TValue>: Represents a filter for a boolean field that is equal to a specific value.
Business Equality related
Equality value filters allow for multiple values indicating that the field must be ANY of those values.
-
EqualsToFilter<TValue>: Represents a filter for a field that is equal to a specific value. -
NotEqualsToFilter<TValue>: Represents a filter for a field that is not equal to a specific value.
Business Comparison related
Comparison value filters allow for a single value indicating that the field must be greater, less, or equal to that value.
-
GreaterThanOrEqualToFilter<TValue>: Represents a filter for a field that is greater than or equal to a specific value. -
GreaterThanFilter<TValue>: Represents a filter for a field that is greater than a specific value. -
LessThanOrEqualToFilter<TValue>: Represents a filter for a field that is less than or equal to a specific value. -
LessThanFilter<TValue>: Represents a filter for a field that is less than a specific value.
Business Nullability related
-
ValuePresenceFilter: Represents a filter for a field to test if it has a value or not.
Business Errors
ProblemDetailsDtoValidationProblemDetailsDtoProblems
Validation
IMessageValidator<TMessage>
Business Services
IIdGenerator
Commands Handlers
HandlerResult<TSuccess>
Business Startup Configuration
AddTdpBusinessServicesAddTdpWolverine
Business Layer Testing
Validation Testing
CheckValidator<TMessage>
Data Layer
Marten Extensions
AppendToStreamApplyFilter
Low Level
ApplyToExpression
Database Errors
Exception.GetDatabaseConstraintException.HasDatabaseConstraint
Business Mappers
TdpCoreDataAccessMapper
DataAccess Startup Configuration
AddTdpMartenAddEventTypesFrom
RestApis Presentation Layer
RestApis Models
RestApis Mappers
MapToActionResult
RestApis Startup Configuration
AddRestApis
Middlewares
TdpExceptionsFilter