Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v5.15.0 #254

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
Bar_ConnectionStrings__Database: Data Source=localhost,1433;Initial Catalog=Foo.Bar;User id=sa;Password=sAPWD23.^0;TrustServerCertificate=true
Bam_ConnectionStrings__Database: Server=localhost;Port=3306;Database=Foo.Bam;Uid=ciuser;Pwd=ciStrong#!Password;AllowUserVariables=true;UseAffectedRows=false;
Bap_ConnectionStrings__Database: Server=localhost;Port=5432;Database=Foo.Bap;User Id=postgres;Pwd=ciStrong#!Password;
Bac_CosmosConnectionString: ${{ secrets.COSMOS_CONNECTION_STRING }}
Cdr_CosmosConnectionString: ${{ secrets.COSMOS_CONNECTION_STRING }}

services:
Expand Down Expand Up @@ -329,4 +330,17 @@ jobs:

- name: Template/SqlServer/EfWs services test
working-directory: ./Foo.EfWs.Bar/Foo.EfWs.Bar.Services.Test
run: dotnet test

# Template - CosmosDB

- name: Template/Cosmos create
run: dotnet new beef --company Foo.Co --appname Bac --datasource Cosmos --output Foo.Co.Bac

- name: Template/Cosmos code-gen
working-directory: ./Foo.Co.Bac/Foo.Co.Bac.CodeGen
run: dotnet run all

- name: Template/Cosmos test
working-directory: ./Foo.Co.Bac
run: dotnet test
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Represents the **NuGet** versions.

## v5.15.0
- *Enhancement:* Added `Operation.Query` boolean to enable support for OData-like query syntax. This leverages the underlying `CoreEx.Data.Querying` (`v3.25.1+`) capabilities to enable. The `Operation.Behavior` has also been extended to support a '`Q`'uery as a shorthand to enable a query-based operation. _Note:_ this is an **awesome** new capability.
- *Enhancement:* Updated the `DatabaseName`, `EntityFrameworkName`, `CosmosName`, `ODataName` and `HttpAgentName` to support both `Type` (existing) and optional `Name` (new). This uses the `Type^Name` syntax supported for other properties with similar purpose. The properties have also had the `Name` suffix renamed to `Type` as this more accurately reflects the property intent (existing names will continue to work with a corresponding warning during code-generation).

## v5.14.2
- *Fixed:* Fixed the data model code-generation to output the `PartitionKey` where specified.
- *Fixed:* Fixed the code-generated `PartitionKey` to be a nullable string.
Expand Down
2 changes: 1 addition & 1 deletion Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>5.14.2</Version>
<Version>5.15.0</Version>
<LangVersion>preview</LangVersion>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
10 changes: 5 additions & 5 deletions docs/Entity-CodeGeneration-Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Provides the _Database Data-layer_ configuration.

Property | Description
-|-
**`databaseName`** | The .NET database interface name (used where `Operation.AutoImplement` is `Database`).<br/>&dagger; Defaults to `IDatabase`. This can be overridden within the `Entity`(s).
**`databaseType`** | The .NET database type and optional name (used where `Operation.AutoImplement` is `Database`).<br/>&dagger; Defaults to `IDatabase`. Should be formatted as `Type` + `^` + `Name`; e.g. `IDatabase^Db`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).
**`databaseSchema`** | The default database schema name.<br/>&dagger; Defaults to `dbo`.
**`databaseProvider`** | The default database schema name. Valid options are: `SqlServer`, `MySQL`, `Postgres`.<br/>&dagger; Defaults to `SqlServer`. Enables specific database provider functionality/formatting/etc. where applicable.
`databaseMapperEx` | Indicates that a `DatabaseMapperEx` will be used; versus, `DatabaseMapper` (which uses Reflection internally).<br/>&dagger; Defaults to `true`. The `DatabaseMapperEx` essentially replaces the `DatabaseMapper` as it is more performant (extended/explicit); this option can be used where leagcy/existing behavior is required.
Expand All @@ -147,7 +147,7 @@ Provides the _Entity Framewotrk (EF) Data-layer_ configuration.

Property | Description
-|-
`entityFrameworkName` | The .NET Entity Framework interface name used where `Operation.AutoImplement` is `EntityFramework`.<br/>&dagger; Defaults to `IEfDb`. This can be overridden within the `Entity`(s).
`entityFrameworkType` | The .NET Entity Framework type and optional name (used where `Operation.AutoImplement` is `EntityFramework`).<br/>&dagger; Defaults to `IEfDb`. Should be formatted as `Type` + `^` + `Name`; e.g. `IEfDb^Ef`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).

<br/>

Expand All @@ -156,7 +156,7 @@ Provides the _CosmosDB Data-layer_ configuration.

Property | Description
-|-
**`cosmosName`** | The .NET Entity Framework interface name used where `Operation.AutoImplement` is `Cosmos`.<br/>&dagger; Defaults to `ICosmosDb`. This can be overridden within the `Entity`(s).
**`cosmosType`** | The .NET Cosmos DB type and name (used where `Operation.AutoImplement` is `Cosmos`).<br/>&dagger; Defaults to `ICosmosDb`. Should be formatted as `Type` + `^` + `Name`; e.g. `ICosmosDb^Cosmos`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).

<br/>

Expand All @@ -165,7 +165,7 @@ Provides the _OData Data-layer_ configuration.

Property | Description
-|-
**`odataName`** | The .NET OData interface name used where `Operation.AutoImplement` is `OData`.<br/>&dagger; Defaults to `IOData`. This can be overridden within the `Entity`(s).
**`odataType`** | The .NET OData interface name used where `Operation.AutoImplement` is `OData`.<br/>&dagger; Defaults to `IOData`. Should be formatted as `Type` + `^` + `Name`; e.g. `IOData^OData`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).

<br/>

Expand All @@ -174,7 +174,7 @@ Provides the _HTTP Agent Data-layer_ configuration.

Property | Description
-|-
**`httpAgentName`** | The default .NET HTTP Agent interface name used where `Operation.AutoImplement` is `HttpAgent`.<br/>&dagger; Defaults to `IHttpAgent`. This can be overridden within the `Entity`(s).
**`httpAgentType`** | The default .NET HTTP Agent interface name used where `Operation.AutoImplement` is `HttpAgent`.<br/>&dagger; Defaults to `IHttpAgent`. Should be formatted as `Type` + `^` + `Name`; e.g. `IHttpAgent^HttpAgent`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).

<br/>

Expand Down
13 changes: 7 additions & 6 deletions docs/Entity-Entity-Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ Provides the _Operation_ configuration. These primarily provide a shorthand to c

Property | Description
-|-
`behavior` | Defines the key CRUD-style behavior (operation types), being 'C'reate, 'G'et (or 'R'ead), 'U'pdate, 'P'atch and 'D'elete). Additionally, GetByArgs ('B') and GetAll ('A') operations that will be automatically generated where not otherwise explicitly specified.<br/>&dagger; Value may only specifiy one or more of the `CGRUDBA` characters (in any order) to define the automatically generated behavior (operations); for example: `CRUPD` or `CRUP` or `rba` (case insensitive). This is shorthand for setting one or more of the following properties: `Get`, `GetByArgs`, `GetAll`, 'Create', `Update`, `Patch` and `Delete`. Where one of these properties is set to either `true` or `false` this will take precedence over the value set for `Behavior`.
`behavior` | Defines the key CRUD-style behavior (operation types), being 'C'reate, 'G'et (or 'R'ead), 'U'pdate, 'P'atch, 'D'elete and `Q`uery). Additionally, `GetByArgs` ('B'), `GetAll` ('A') and `GetByQuery` ('Q') operations configuration will be automatically inferred where not otherwise explicitly specified.<br/>&dagger; Value may only specifiy one or more of the `CGRUDBAQ` characters (in any order) to define the automatically generated behavior (operations); for example: `CRUPD` or `CRUP` or `rba` (case insensitive). This is shorthand for setting one or more of the following properties: `Get`, `GetByArgs`, `GetAll`, 'Create', `Update`, `Patch` and `Delete`. Where one of these properties is set to either `true` or `false` this will take precedence over the value set for `Behavior`.
`get` | Indicates that a `Get` operation will be automatically generated where not otherwise explicitly specified.
`getByArgs` | Indicates that a `GetByArgs` operation will be automatically generated where not otherwise explicitly specified.
`getAll` | Indicates that a `GetAll` operation will be automatically generated where not otherwise explicitly specified.
`getByQuery` | Indicates that a `GetByQuery` operation will be automatically generated where not otherwise explicitly specified.
`create` | Indicates that a `Create` operation will be automatically generated where not otherwise explicitly specified.
`update` | Indicates that a `Update` operation will be automatically generated where not otherwise explicitly specified.
`patch` | Indicates that a `Patch` operation will be automatically generated where not otherwise explicitly specified.
Expand Down Expand Up @@ -217,7 +218,7 @@ Provides the specific _Database (ADO.NET)_ configuration where `AutoImplement` i

Property | Description
-|-
**`databaseName`** | The .NET database interface name (used where `AutoImplement` is `Database`).<br/>&dagger; Defaults to the `CodeGeneration.DatabaseName` configuration property (its default value is `IDatabase`).
**`databaseType`** | The .NET database type and optional name (used where `AutoImplement` is `Database`).<br/>&dagger; Defaults to the `CodeGeneration.DatabaseName` configuration property (its default value is `IDatabase`). Should be formatted as `Type` + `^` + `Name`.
**`databaseSchema`** | The database schema name (used where `AutoImplement` is `Database`).<br/>&dagger; Defaults to `dbo`.
`databaseMapperInheritsFrom` | The name of the `Mapper` that the generated Database `Mapper` inherits from.
`databaseCustomMapper` | Indicates that a custom Database `Mapper` will be used; i.e. not generated.<br/>&dagger; Otherwise, by default, a `Mapper` will be generated.
Expand All @@ -230,7 +231,7 @@ Provides the specific _Entity Framework (EF)_ configuration where `AutoImplement

Property | Description
-|-
**`entityFrameworkName`** | The .NET Entity Framework interface name used where `AutoImplement` is `EntityFramework`.<br/>&dagger; Defaults to `CodeGeneration.EntityFrameworkName`.
**`entityFrameworkType`** | The .NET Entity Framework type and optyional name used where `AutoImplement` is `EntityFramework`.<br/>&dagger; Defaults to `CodeGeneration.EntityFrameworkName`. Should be formatted as `Type` + `^` + `Name`.
**`entityFrameworkModel`** | The corresponding Entity Framework model name (required where `AutoImplement` is `EntityFramework`).
`entityFrameworkCustomMapper` | Indicates that a custom Entity Framework `Mapper` will be used; i.e. not generated.<br/>&dagger; Otherwise, by default, a `Mapper` will be generated.
`entityFrameworkMapperBase` | The EntityFramework data-layer name that should be used for base mappings.
Expand All @@ -242,7 +243,7 @@ Provides the specific _Cosmos_ configuration where `AutoImplement` is `Cosmos`.

Property | Description
-|-
**`cosmosName`** | The .NET Cosmos interface name used where `AutoImplement` is `Cosmos`.<br/>&dagger; Defaults to the `CodeGeneration.CosmosName` configuration property (its default value is `ICosmosDb`).
**`cosmosType`** | The .NET Cosmos DB type and optional name used where `AutoImplement` is `Cosmos`.<br/>&dagger; Defaults to the `CodeGeneration.CosmosName` configuration property (its default value is `ICosmosDb`). Should be formatted as `Type` + `^` + `Name`.
**`cosmosModel`** | The corresponding Cosmos model name (required where `AutoImplement` is `Cosmos`).
**`cosmosContainerId`** | The Cosmos `ContainerId` required where `AutoImplement` is `Cosmos`.
`cosmosPartitionKey` | The C# code to be used for setting the optional Cosmos `PartitionKey` where `AutoImplement` is `Cosmos`.<br/>&dagger; The value `PartitionKey.None` can be specified. Literals will need to be quoted.
Expand All @@ -258,7 +259,7 @@ Provides the specific _OData_ configuration where `AutoImplement` is `OData`.

Property | Description
-|-
**`odataName`** | The .NET OData interface name used where `AutoImplement` is `OData`.<br/>&dagger; Defaults to the `CodeGeneration.ODataName` configuration property (its default value is `IOData`).
**`odataType`** | The .NET OData type and optional name used where `AutoImplement` is `OData`.<br/>&dagger; Defaults to the `CodeGeneration.ODataName` configuration property (its default value is `IOData`). Should be formatted as `Type` + `^` + `Name`.
**`odataModel`** | The corresponding OData model name (required where `AutoImplement` is `OData`).
**`odataCollectionName`** | The name of the underlying OData collection where `AutoImplement` is `OData`.<br/>&dagger; The underlying `Simple.OData.Client` will attempt to infer.
`odataCustomMapper` | Indicates that a custom OData `Mapper` will be used; i.e. not generated.<br/>&dagger; Otherwise, by default, a `Mapper` will be generated.
Expand All @@ -271,7 +272,7 @@ Provides the specific _HTTP Agent_ configuration where `AutoImplement` is `HttpA

Property | Description
-|-
**`httpAgentName`** | The .NET HTTP Agent interface name used where `Operation.AutoImplement` is `HttpAgent`.<br/>&dagger; Defaults to `CodeGeneration.HttpAgentName` configuration property (its default value is `IHttpAgent`).
**`httpAgentType`** | The .NET HTTP Agent type and optional name used where `Operation.AutoImplement` is `HttpAgent`.<br/>&dagger; Defaults to `CodeGeneration.HttpAgentName` configuration property (its default value is `IHttpAgent`). Should be formatted as `Type` + `^` + `Name`.
`httpAgentRoutePrefix` | The base HTTP Agent API route where `Operation.AutoImplement` is `HttpAgent`.<br/>&dagger; This is the base (prefix) `URI` for the HTTP Agent endpoint and can be further extended when defining the underlying `Operation`(s).
**`httpAgentModel`** | The corresponding HTTP Agent model name (required where `AutoImplement` is `HttpAgent`).<br/>&dagger; This can be overridden within the `Operation`(s).
`httpAgentReturnModel` | The corresponding HTTP Agent model name (required where `AutoImplement` is `HttpAgent`).<br/>&dagger; This can be overridden within the `Operation`(s).
Expand Down
1 change: 1 addition & 0 deletions docs/Entity-Operation-Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Property | Description
`text` | The text for use in comments.<br/>&dagger; The `Text` will be defaulted for all the `Operation.Type` options with the exception of `Custom`. To create a `<see cref="XXX"/>` within use moustache shorthand (e.g. {{Xxx}}). To have the text used as-is prefix with a `+` plus-sign character.
**`primaryKey`** | Indicates whether the properties marked as a primary key (`Property.PrimaryKey`) are to be used as the parameters.<br/>&dagger; This simplifies the specification of these properties as parameters versus having to declare each specifically. Each of the parameters will also be set to be mandatory.
**`paging`** | Indicates whether a `PagingArgs` argument is to be added to the operation to enable (standardized) paging related logic.
**`query`** | Indicates whether a `QueryArgs` argument is to be added to the operation to enable OData-like $filter and $orderby related logic.
`valueType` | The .NET value parameter `Type` for the operation.<br/>&dagger; Defaults to the parent `Entity.Name` where the `Operation.Type` options are `Create` or `Update`.
`returnType` | The .NET return `Type` for the operation.<br/>&dagger; Defaults to the parent `Entity.Name` where the `Operation.Type` options are `Get`, `GetColl`, `Create` or `Update`; otherwise, defaults to `void`.
`returnTypeNullable` | Indicates whether the `ReturnType` is nullable for the operation.<br/>&dagger; Will be inferred where the `ReturnType` is denoted as nullable; i.e. suffixed by a `?`. Additionally a `Type` of `Get` will default to `true` where not specified.
Expand Down
4 changes: 2 additions & 2 deletions samples/Cdr.Banking/Cdr.Banking.Api/Cdr.Banking.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CoreEx.AspNetCore" Version="3.24.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.7.0" />
<PackageReference Include="CoreEx.AspNetCore" Version="3.25.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.7.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cdr.Banking.Business\Cdr.Banking.Business.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ public Task<IActionResult> GetAccounts([FromQuery(Name="product-category")] stri
return _webApi.GetWithResultAsync<AccountCollectionResult>(Request, p => _manager.GetAccountsAsync(args, p.RequestOptions.Paging), alternateStatusCode: HttpStatusCode.NoContent);
}

/// <summary>
/// Get all accounts.
/// </summary>
/// <returns>The <c>Account</c> array</returns>
[Tags("Banking", "Accounts")]
[HttpGet("api/v1/banking/accounts/query", Name="Account_GetAccountsQuery")]
[Paging]
[Query]
[ProducesResponseType(typeof(Common.Entities.AccountCollection), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
public Task<IActionResult> GetAccountsQuery()
=> _webApi.GetWithResultAsync<AccountCollectionResult>(Request, p => _manager.GetAccountsQueryAsync(p.RequestOptions.Query, p.RequestOptions.Paging), alternateStatusCode: HttpStatusCode.NoContent);

/// <summary>
/// Get <c>AccountDetail</c>.
/// </summary>
Expand Down
11 changes: 9 additions & 2 deletions samples/Cdr.Banking/Cdr.Banking.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ public void ConfigureServices(IServiceCollection services)
.AddValidators<AccountManager>();

// Add the cosmos database.
services.AddSingleton<ICosmos>(sp =>
services.AddSingleton(sp =>
{
var settings = sp.GetRequiredService<BankingSettings>();
var cco = new AzCosmos.CosmosClientOptions { SerializerOptions = new AzCosmos.CosmosSerializationOptions { PropertyNamingPolicy = AzCosmos.CosmosPropertyNamingPolicy.CamelCase, IgnoreNullValues = true } };
return new CosmosDb(new AzCosmos.CosmosClient(settings.CosmosConnectionString, cco).GetDatabase(settings.CosmosDatabaseId), sp.GetRequiredService<CoreEx.Mapping.IMapper>());
return new AzCosmos.CosmosClient(settings.CosmosConnectionString, cco);
});

services.AddCosmosDb<ICosmos>(sp =>
{
var settings = sp.GetRequiredService<BankingSettings>();
return new CosmosDb(sp.GetRequiredService<AzCosmos.CosmosClient>().GetDatabase(settings.CosmosDatabaseId), sp.GetRequiredService<CoreEx.Mapping.IMapper>());
});

// Add the generated reference data services.
Expand All @@ -60,6 +66,7 @@ public void ConfigureServices(IServiceCollection services)
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Cdr.Banking API", Version = "v1" });
options.OperationFilter<AcceptsBodyOperationFilter>(); // Needed to support AcceptsBodyAttribute where body parameter not explicitly defined.
options.OperationFilter<PagingOperationFilter>(); // Needed to support PagingAttribute where PagingArgs parameter not explicitly defined.
options.OperationFilter<QueryOperationFilter>(); // Needed to support QueryAttribute where QueryArgs parameter not explicitly defined.
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<Folder Include="DataSvc\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CoreEx.AspNetCore" Version="3.24.1" />
<PackageReference Include="CoreEx.Cosmos" Version="3.24.1" />
<PackageReference Include="CoreEx.Validation" Version="3.24.1" />
<PackageReference Include="CoreEx.AspNetCore" Version="3.25.1" />
<PackageReference Include="CoreEx.Cosmos" Version="3.25.1" />
<PackageReference Include="CoreEx.Validation" Version="3.25.1" />
</ItemGroup>
</Project>
Loading
Loading