Skip to content

Commit

Permalink
Introduce AutoMapper (Avanade#150)
Browse files Browse the repository at this point in the history
* Introduce AutoMapper.

* AutoMapper for My.Hr and Cdr.Banking.

* ReferenceDataData changes.

* Update YAML/XML documentation and schemas.

* Updated solution template.

* Additional tweaks.

* - Rename types to Int32 and add corresponding Int64 where applicable.
- Move ILogicallyDeleted and IMultiTenant to Beef.Abstractions.

* Add validation `BetweenRule`.

* Grpc AutoMapper introduction.

* Re-gen schemas and doco.

* Updated Grpc version and changelog.

* Hard decision made to remove existing EntityMapper and go all in with AutoMapper (except for Beef.Data.Database).

* Re-jig Mapper artefact location between Beef.Abstractions, Beef.Core and Beef.Data.Database.

* Run unit tests and correct.

* - Remove property Mappers for EF, Cosmos & OData (no longer required when using AutoMapper).
- Re-gen schemas and doco.

* Fix minor gen comment issue.
  • Loading branch information
chullybun authored Aug 16, 2021
1 parent 27a2e50 commit 0fcc323
Show file tree
Hide file tree
Showing 223 changed files with 3,057 additions and 5,804 deletions.
4 changes: 4 additions & 0 deletions docs/Beef-Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The following represent the available rules:

Rule | Description
-|-
`BetweenRule` | Provides a comparision validation between a specified from and to value.
`CollectionRule` | Provides collection (`IEnumerable`) validation including `MinCount`, `MaxCount`, per item validation `CollectionRuleItem` and duplicate checking.
`CommonRule` | Provides for integrating a common validation against a specified property.
`ComparePropertyRule` | Provides a comparision validation against another property within the same entity; also confirms other property has no errors prior to comparison.
Expand Down Expand Up @@ -70,6 +71,7 @@ The following represent the available extension methods:
Extension method | Description | Underlying rule
-|-|-
`AreValid()` | Adds a *reference data list* validation. | `ReferenceDataSidListRule`
`Between()` | Adds a *between comparision* validation. | `BetweenRule`
`Collection()` | Adds a *collection* validation. | `CollectionRule`
`CompareProperty()` | Adds a *property comparison* validation. | `ComparePropertyRule`
`CompareValue()` | Adds a *value comparison* validation. | `CompareValueRule`
Expand Down Expand Up @@ -108,6 +110,8 @@ All error messages are managed as an embedded resources accessible via the `Vali
Property | Format string
-|-
`AllowNegativesFormat` | {0} must not be negative.
`BetweenInclusiveFormat` | {0} must be between {2} and {3}.
`BetweenExclusiveFormat` | {0} must be between {2} and {3} (exclusive).
`CollectionNullItemFormat` | {0} contains one or more items that are not specified.
`CompareEqualFormat` | {0} must be equal to {2}.
`CompareGreaterThanEqualFormat` | {0} must be greater than or equal to {2}.
Expand Down
2 changes: 1 addition & 1 deletion docs/Entity-CodeGeneration-Config-Xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Provides the generic _Data-layer_ configuration.

Property | Description
-|-
`MapperDefaultRefDataConverter` | The default Reference Data property `Converter` used by the generated `Mapper`(s) where not specifically defined. Valid options are: `ReferenceDataCodeConverter`, `ReferenceDataCodeConverter{T}`, `ReferenceDataCodeConverter<T>`, `ReferenceDataInt32IdConverter`, `ReferenceDataInt32IdConverter{T}`, `ReferenceDataInt32IdConverter<T>`, `ReferenceDataNullableInt32IdConverter`, `ReferenceDataNullableInt32IdConverter{T}`, `ReferenceDataNullableInt32IdConverter<T>`, `ReferenceDataGuidIdConverter`, `ReferenceDataGuidIdConverter{T}`, `ReferenceDataGuidIdConverter<T>`, `ReferenceDataNullableGuidIdConverter`, `ReferenceDataNullableGuidIdConverter{T}`, `ReferenceDataNullableGuidIdConverter<T>`. Defaults to `ReferenceDataCodeConverter<T>`. Where this value is suffixed by `<T>` or `{T}` this will automatically set `Property.DataConverterIsGeneric` to `true`.
`MapperDefaultRefDataConverter` | The default Reference Data property `Converter` used by the generated `Mapper`(s) where not specifically defined. Valid options are: `ReferenceDataCodeConverter`, `ReferenceDataCodeConverter{T}`, `ReferenceDataCodeConverter<T>`, `ReferenceDataInt32IdConverter`, `ReferenceDataInt32IdConverter{T}`, `ReferenceDataInt32IdConverter<T>`, `ReferenceDataNullableInt32IdConverter`, `ReferenceDataNullableInt32IdConverter{T}`, `ReferenceDataNullableInt32IdConverter<T>`, `ReferenceDataInt64IdConverter`, `ReferenceDataInt64IdConverter{T}`, `ReferenceDataInt64IdConverter<T>`, `ReferenceDataNullableInt64IdConverter`, `ReferenceDataNullableInt64IdConverter{T}`, `ReferenceDataNullableInt64IdConverter<T>`, `ReferenceDataGuidIdConverter`, `ReferenceDataGuidIdConverter{T}`, `ReferenceDataGuidIdConverter<T>`, `ReferenceDataNullableGuidIdConverter`, `ReferenceDataNullableGuidIdConverter{T}`, `ReferenceDataNullableGuidIdConverter<T>`. Defaults to `ReferenceDataCodeConverter<T>`. Where this value is suffixed by `<T>` or `{T}` this will automatically set `Property.DataConverterIsGeneric` to `true`.
`DataUsingNamespace` | The additional Namespace using statement to be added to the generated `Data` code.

<br/>
Expand Down
2 changes: 1 addition & 1 deletion docs/Entity-CodeGeneration-Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Provides the generic _Data-layer_ configuration.

Property | Description
-|-
`refDataDefaultMapperConverter` | The default Reference Data property `Converter` used by the generated `Mapper`(s) where not specifically defined. Valid options are: `ReferenceDataCodeConverter`, `ReferenceDataCodeConverter{T}`, `ReferenceDataCodeConverter<T>`, `ReferenceDataInt32IdConverter`, `ReferenceDataInt32IdConverter{T}`, `ReferenceDataInt32IdConverter<T>`, `ReferenceDataNullableInt32IdConverter`, `ReferenceDataNullableInt32IdConverter{T}`, `ReferenceDataNullableInt32IdConverter<T>`, `ReferenceDataGuidIdConverter`, `ReferenceDataGuidIdConverter{T}`, `ReferenceDataGuidIdConverter<T>`, `ReferenceDataNullableGuidIdConverter`, `ReferenceDataNullableGuidIdConverter{T}`, `ReferenceDataNullableGuidIdConverter<T>`. Defaults to `ReferenceDataCodeConverter<T>`. Where this value is suffixed by `<T>` or `{T}` this will automatically set `Property.DataConverterIsGeneric` to `true`.
`refDataDefaultMapperConverter` | The default Reference Data property `Converter` used by the generated `Mapper`(s) where not specifically defined. Valid options are: `ReferenceDataCodeConverter`, `ReferenceDataCodeConverter{T}`, `ReferenceDataCodeConverter<T>`, `ReferenceDataInt32IdConverter`, `ReferenceDataInt32IdConverter{T}`, `ReferenceDataInt32IdConverter<T>`, `ReferenceDataNullableInt32IdConverter`, `ReferenceDataNullableInt32IdConverter{T}`, `ReferenceDataNullableInt32IdConverter<T>`, `ReferenceDataInt64IdConverter`, `ReferenceDataInt64IdConverter{T}`, `ReferenceDataInt64IdConverter<T>`, `ReferenceDataNullableInt64IdConverter`, `ReferenceDataNullableInt64IdConverter{T}`, `ReferenceDataNullableInt64IdConverter<T>`, `ReferenceDataGuidIdConverter`, `ReferenceDataGuidIdConverter{T}`, `ReferenceDataGuidIdConverter<T>`, `ReferenceDataNullableGuidIdConverter`, `ReferenceDataNullableGuidIdConverter{T}`, `ReferenceDataNullableGuidIdConverter<T>`. Defaults to `ReferenceDataCodeConverter<T>`. Where this value is suffixed by `<T>` or `{T}` this will automatically set `Property.DataConverterIsGeneric` to `true`.
`dataUsingNamespace` | The additional Namespace using statement to be added to the generated `Data` code.

<br/>
Expand Down
9 changes: 4 additions & 5 deletions docs/Entity-Entity-Config-Xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Property | Description
`EntityScope` | The entity scope option. Valid options are: `Common`, `Business`, `Autonomous`. Defaults to the `CodeGeneration.EntityScope`. Determines where the entity is scoped/defined, being `Common` or `Business` (i.e. not externally visible). Additionally, there is a special case of `Autonomous` where both a `Common` and `Business` entity are generated (where only the latter inherits from `EntityBase`, etc).
`PrivateName` | The overriding private name. Overrides the `Name` to be used for private fields. By default reformatted from `Name`; e.g. `FirstName` as `_firstName`.
`ArgumentName` | The overriding argument name. Overrides the `Name` to be used for argument parameters. By default reformatted from `Name`; e.g. `FirstName` as `firstName`.
`ConstType` | The Const .NET Type option. Valid options are: `int`, `Guid`, `string`. The .NET Type to be used for the `const` values. Defaults to `string`.
`ConstType` | The Const .NET Type option. Valid options are: `int`, `long`, `Guid`, `string`. The .NET Type to be used for the `const` values. Defaults to `string`.
`IsInitialOverride` | Indicates whether to override the `ICleanup.IsInitial` property. Set to either `true` or `false` to override as specified; otherwise, `null` to check each property. Defaults to `null`.

<br/>
Expand All @@ -52,7 +52,7 @@ Provides the _Reference Data_ configuration.

Property | Description
-|-
**`RefDataType`** | The Reference Data identifier Type option. Valid options are: `int`, `Guid`, `string`. Required to identify an entity as being Reference Data. Specifies the underlying .NET Type used for the Reference Data identifier.
**`RefDataType`** | The Reference Data identifier Type option. Valid options are: `int`, `long`, `Guid`, `string`. Required to identify an entity as being Reference Data. Specifies the underlying .NET Type used for the Reference Data identifier.
`RefDataText` | Indicates whether a corresponding `Text` property is added when generating a Reference Data `Property` overriding the `CodeGeneration.RefDataText` selection. This is used where serializing within the Web API`Controller` and the `ExecutionContext.IsRefDataTextSerializationEnabled` is set to `true` (which is automatically set where the url contains `$text=true`).
`RefDataSortOrder` | The Reference Data sort order option. Valid options are: `SortOrder`, `Id`, `Code`, `Text`. Specifies the default sort order for the underlying Reference Data collection. Defaults to `SortOrder`.
`RefDataStringFormat` | The Reference Data `ToString` composite format. The string format supports the standard composite formatting; where the following indexes are used: `{0}` for `Id`, `{1}` for `Code` and `{2}` for `Text`. Defaults to `{2}`.
Expand All @@ -65,9 +65,9 @@ Provides the _Entity class_ configuration.
Property | Description
-|-
`EntityUsing` | The namespace for the non Reference Data entities (adds as a c# <c>using</c> statement). Valid options are: `Common`, `Business`, `All`, `None`. Defaults to `EntityScope` (`Autonomous` will result in `Business`). A value of `Common` will add `.Common.Entities`, `Business` will add `.Business.Entities`, `All` to add both, and `None` to exclude any.
`Inherits` | The base class that the entity inherits from. Defaults to `EntityBase` for a standard entity. For Reference Data it will default to `ReferenceDataBaseInt` or `ReferenceDataBaseGuid` depending on the corresponding `RefDataType` value. See `OmitEntityBase` if the desired outcome is to not inherit from any of the aforementioned base classes.
`Inherits` | The base class that the entity inherits from. Defaults to `EntityBase` for a standard entity. For Reference Data it will default to `ReferenceDataBaseXxx` depending on the corresponding `RefDataType` value. See `OmitEntityBase` if the desired outcome is to not inherit from any of the aforementioned base classes.
`Implements` | The list of comma separated interfaces that are to be declared for the entity class.
`AutoInferImplements` | Indicates whether to automatically infer the interface implements for the entity from the properties declared. Will attempt to infer the following: `IGuidIdentifier`, `IIntIdentifier`, `IStringIdentifier`, `IETag` and `IChangeLog`. Defaults to `true`.
`AutoInferImplements` | Indicates whether to automatically infer the interface implements for the entity from the properties declared. Will attempt to infer the following: `IGuidIdentifier`, `IInt32Identifier`, `IInt64Identifier`, `IStringIdentifier`, `IETag` and `IChangeLog`. Defaults to `true`.
`Abstract` | Indicates whether the class should be defined as abstract.
`GenericWithT` | Indicates whether the class should be defined as a generic with a single parameter `T`.
`Namespace` | The entity namespace to be appended. Appended to the end of the standard structure as follows: `{Company}.{AppName}.Common.Entities.{Namespace}`.
Expand Down Expand Up @@ -169,7 +169,6 @@ Provides the generic _Data-layer_ configuration.
Property | Description
-|-
**`AutoImplement`** | The data source auto-implementation option. Valid options are: `Database`, `EntityFramework`, `Cosmos`, `OData`, `None`. Defaults to `None`. Indicates that the implementation for the underlying `Operations` will be auto-implemented using the selected data source (unless explicity overridden). When selected some of the related attributes will also be required (as documented). Additionally, the `AutoImplement` indicator must be selected for each underlying `Operation` that is to be auto-implemented.
`MapperAddStandardProperties` | Indicates that the `AddStandardProperties` method call is to be included for the generated (corresponding) `Mapper`. Defaults to `true`.
`DataConstructor` | The access modifier for the generated `Data` constructor. Valid options are: `Public`, `Private`, `Protected`. Defaults to `Public`.
**`DataCtorParams`** | The comma seperated list of additional (non-inferred) Dependency Injection (DI) parameters for the generated `Data` constructor. Each constructor parameter should be formatted as `Type` + `^` + `Name`; e.g. `IConfiguration^Config`. Where the `Name` portion is not specified it will be inferred. Where the `Type` matches an already inferred value it will be ignored.
`DataExtensions` | Indicates whether the `Data` extensions logic should be generated. This can be overridden using `Operation.DataExtensions`.
Expand Down
9 changes: 4 additions & 5 deletions docs/Entity-Entity-Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Property | Description
`entityScope` | The entity scope option. Valid options are: `Common`, `Business`, `Autonomous`. Defaults to the `CodeGeneration.EntityScope`. Determines where the entity is scoped/defined, being `Common` or `Business` (i.e. not externally visible). Additionally, there is a special case of `Autonomous` where both a `Common` and `Business` entity are generated (where only the latter inherits from `EntityBase`, etc).
`privateName` | The overriding private name. Overrides the `Name` to be used for private fields. By default reformatted from `Name`; e.g. `FirstName` as `_firstName`.
`argumentName` | The overriding argument name. Overrides the `Name` to be used for argument parameters. By default reformatted from `Name`; e.g. `FirstName` as `firstName`.
`constType` | The Const .NET Type option. Valid options are: `int`, `Guid`, `string`. The .NET Type to be used for the `const` values. Defaults to `string`.
`constType` | The Const .NET Type option. Valid options are: `int`, `long`, `Guid`, `string`. The .NET Type to be used for the `const` values. Defaults to `string`.
`isInitialOverride` | Indicates whether to override the `ICleanup.IsInitial` property. Set to either `true` or `false` to override as specified; otherwise, `null` to check each property. Defaults to `null`.

<br/>
Expand All @@ -70,7 +70,7 @@ Provides the _Reference Data_ configuration.

Property | Description
-|-
**`refDataType`** | The Reference Data identifier Type option. Valid options are: `int`, `Guid`, `string`. Required to identify an entity as being Reference Data. Specifies the underlying .NET Type used for the Reference Data identifier.
**`refDataType`** | The Reference Data identifier Type option. Valid options are: `int`, `long`, `Guid`, `string`. Required to identify an entity as being Reference Data. Specifies the underlying .NET Type used for the Reference Data identifier.
`refDataText` | Indicates whether a corresponding `Text` property is added when generating a Reference Data `Property` overriding the `CodeGeneration.RefDataText` selection. This is used where serializing within the Web API`Controller` and the `ExecutionContext.IsRefDataTextSerializationEnabled` is set to `true` (which is automatically set where the url contains `$text=true`).
`refDataSortOrder` | The Reference Data sort order option. Valid options are: `SortOrder`, `Id`, `Code`, `Text`. Specifies the default sort order for the underlying Reference Data collection. Defaults to `SortOrder`.
`refDataStringFormat` | The Reference Data `ToString` composite format. The string format supports the standard composite formatting; where the following indexes are used: `{0}` for `Id`, `{1}` for `Code` and `{2}` for `Text`. Defaults to `{2}`.
Expand All @@ -83,9 +83,9 @@ Provides the _Entity class_ configuration.
Property | Description
-|-
`entityUsing` | The namespace for the non Reference Data entities (adds as a c# <c>using</c> statement). Valid options are: `Common`, `Business`, `All`, `None`. Defaults to `EntityScope` (`Autonomous` will result in `Business`). A value of `Common` will add `.Common.Entities`, `Business` will add `.Business.Entities`, `All` to add both, and `None` to exclude any.
`inherits` | The base class that the entity inherits from. Defaults to `EntityBase` for a standard entity. For Reference Data it will default to `ReferenceDataBaseInt` or `ReferenceDataBaseGuid` depending on the corresponding `RefDataType` value. See `OmitEntityBase` if the desired outcome is to not inherit from any of the aforementioned base classes.
`inherits` | The base class that the entity inherits from. Defaults to `EntityBase` for a standard entity. For Reference Data it will default to `ReferenceDataBaseXxx` depending on the corresponding `RefDataType` value. See `OmitEntityBase` if the desired outcome is to not inherit from any of the aforementioned base classes.
`implements` | The list of comma separated interfaces that are to be declared for the entity class.
`implementsAutoInfer` | Indicates whether to automatically infer the interface implements for the entity from the properties declared. Will attempt to infer the following: `IGuidIdentifier`, `IIntIdentifier`, `IStringIdentifier`, `IETag` and `IChangeLog`. Defaults to `true`.
`implementsAutoInfer` | Indicates whether to automatically infer the interface implements for the entity from the properties declared. Will attempt to infer the following: `IGuidIdentifier`, `IInt32Identifier`, `IInt64Identifier`, `IStringIdentifier`, `IETag` and `IChangeLog`. Defaults to `true`.
`abstract` | Indicates whether the class should be defined as abstract.
`genericWithT` | Indicates whether the class should be defined as a generic with a single parameter `T`.
`namespace` | The entity namespace to be appended. Appended to the end of the standard structure as follows: `{Company}.{AppName}.Common.Entities.{Namespace}`.
Expand Down Expand Up @@ -187,7 +187,6 @@ Provides the generic _Data-layer_ configuration.
Property | Description
-|-
**`autoImplement`** | The data source auto-implementation option. Valid options are: `Database`, `EntityFramework`, `Cosmos`, `OData`, `None`. Defaults to `None`. Indicates that the implementation for the underlying `Operations` will be auto-implemented using the selected data source (unless explicity overridden). When selected some of the related attributes will also be required (as documented). Additionally, the `AutoImplement` indicator must be selected for each underlying `Operation` that is to be auto-implemented.
`mapperAddStandardProperties` | Indicates that the `AddStandardProperties` method call is to be included for the generated (corresponding) `Mapper`. Defaults to `true`.
`dataCtor` | The access modifier for the generated `Data` constructor. Valid options are: `Public`, `Private`, `Protected`. Defaults to `Public`.
`dataCtorParams` | The list of additional (non-inferred) Dependency Injection (DI) parameters for the generated `Data` constructor. Each constructor parameter should be formatted as `Type` + `^` + `Name`; e.g. `IConfiguration^Config`. Where the `Name` portion is not specified it will be inferred. Where the `Type` matches an already inferred value it will be ignored.
`dataExtensions` | Indicates whether the `Data` extensions logic should be generated. This can be overridden using `Operation.DataExtensions`.
Expand Down
Loading

0 comments on commit 0fcc323

Please sign in to comment.