Skip to content

Commit

Permalink
Agent code-gen simplification.
Browse files Browse the repository at this point in the history
  • Loading branch information
chullybun committed Oct 23, 2024
1 parent edda860 commit 1ee170a
Show file tree
Hide file tree
Showing 48 changed files with 252 additions and 332 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Represents the **NuGet** versions.

## v5.17.1
- *Fixed:* The database console `Script` command execution has been updated to output to the correct directory path.
- *Fixed:* The `Agent` code-generation artefacts have been further simplified/improved.

## v5.17.0
- *Enhancement:* The `Common`-project related code-generated artefacts have all been updated to leverage `global using` and file scoped namespace declarations.
Expand Down
2 changes: 1 addition & 1 deletion samples/Cdr.Banking/Cdr.Banking.Api/Cdr.Banking.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CoreEx.AspNetCore" Version="3.27.2" />
<PackageReference Include="CoreEx.AspNetCore" Version="3.27.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.9.0" />
</ItemGroup>
<ItemGroup>
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.27.2" />
<PackageReference Include="CoreEx.Cosmos" Version="3.27.2" />
<PackageReference Include="CoreEx.Validation" Version="3.27.2" />
<PackageReference Include="CoreEx.AspNetCore" Version="3.27.3" />
<PackageReference Include="CoreEx.Cosmos" Version="3.27.3" />
<PackageReference Include="CoreEx.Validation" Version="3.27.3" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,28 @@ namespace Cdr.Banking.Common.Agents;
/// <summary>
/// Provides the <see cref="Account"/> HTTP agent.
/// </summary>
public partial class AccountAgent : TypedHttpClientBase<AccountAgent>, IAccountAgent
/// <param name="client">The underlying <see cref="HttpClient"/>.</param>
/// <param name="jsonSerializer">The optional <see cref="IJsonSerializer"/>.</param>
/// <param name="executionContext">The optional <see cref="CoreEx.ExecutionContext"/>.</param>
public partial class AccountAgent(HttpClient client, IJsonSerializer? jsonSerializer = null, CoreEx.ExecutionContext? executionContext = null) : TypedHttpClientBase<AccountAgent>(client, jsonSerializer, executionContext), IAccountAgent
{
/// <summary>
/// Initializes a new instance of the <see cref="AccountAgent"/> class.
/// </summary>
/// <param name="client">The underlying <see cref="HttpClient"/>.</param>
/// <param name="jsonSerializer">The optional <see cref="IJsonSerializer"/>.</param>
/// <param name="executionContext">The optional <see cref="CoreEx.ExecutionContext"/>.</param>
public AccountAgent(HttpClient client, IJsonSerializer? jsonSerializer = null, CoreEx.ExecutionContext? executionContext = null) : base(client, jsonSerializer, executionContext) { }

/// <inheritdoc/>
public Task<HttpResult<AccountCollectionResult>> GetAccountsAsync(AccountArgs? args, PagingArgs? paging = null, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync<AccountCollectionResult>("api/v1/banking/accounts", requestOptions: requestOptions.IncludePaging(paging), args: HttpArgs.Create(new HttpArg<AccountArgs?>("args", args, HttpArgType.FromUriUseProperties)), cancellationToken: cancellationToken);
=> GetAsync<AccountCollectionResult>("api/v1/banking/accounts", requestOptions.IncludePaging(paging), [new HttpArg<AccountArgs?>("args", args, HttpArgType.FromUriUseProperties)], cancellationToken);

/// <inheritdoc/>
public Task<HttpResult<AccountCollectionResult>> GetAccountsQueryAsync(QueryArgs? query = null, PagingArgs? paging = null, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync<AccountCollectionResult>("api/v1/banking/accounts/query", requestOptions: requestOptions.IncludeQuery(query).IncludePaging(paging), args: HttpArgs.Create(), cancellationToken: cancellationToken);
=> GetAsync<AccountCollectionResult>("api/v1/banking/accounts/query", requestOptions: requestOptions.IncludeQuery(query).IncludePaging(paging), cancellationToken: cancellationToken);

/// <inheritdoc/>
public Task<HttpResult<AccountDetail?>> GetDetailAsync(string? accountId, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync<AccountDetail?>("api/v1/banking/accounts/{accountId}", requestOptions: requestOptions, args: HttpArgs.Create(new HttpArg<string?>("accountId", accountId)), cancellationToken: cancellationToken);
=> GetAsync<AccountDetail?>("api/v1/banking/accounts/{accountId}", requestOptions, [new HttpArg<string?>("accountId", accountId)], cancellationToken);

/// <inheritdoc/>
public Task<HttpResult<Balance?>> GetBalanceAsync(string? accountId, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync<Balance?>("api/v1/banking/accounts/{accountId}/balance", requestOptions: requestOptions, args: HttpArgs.Create(new HttpArg<string?>("accountId", accountId)), cancellationToken: cancellationToken);
=> GetAsync<Balance?>("api/v1/banking/accounts/{accountId}/balance", requestOptions, [new HttpArg<string?>("accountId", accountId)], cancellationToken);

/// <inheritdoc/>
public Task<HttpResult> GetStatementAsync(string? accountId, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync("api/v1/banking/accounts/{accountId}/statement", requestOptions: requestOptions, args: HttpArgs.Create(new HttpArg<string?>("accountId", accountId)), cancellationToken: cancellationToken);
=> GetAsync("api/v1/banking/accounts/{accountId}/statement", requestOptions, [new HttpArg<string?>("accountId", accountId)], cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,34 @@ namespace Cdr.Banking.Common.Agents;
/// <summary>
/// Provides the <b>ReferenceData</b> HTTP agent.
/// </summary>
public partial class ReferenceDataAgent : TypedHttpClientBase<ReferenceDataAgent>, IReferenceDataAgent
/// <param name="client">The underlying <see cref="HttpClient"/>.</param>
/// <param name="jsonSerializer">The optional <see cref="IJsonSerializer"/>.</param>
/// <param name="executionContext">The optional <see cref="CoreEx.ExecutionContext"/>.</param>
public partial class ReferenceDataAgent(HttpClient client, IJsonSerializer? jsonSerializer = null, CoreEx.ExecutionContext? executionContext = null) : TypedHttpClientBase<ReferenceDataAgent>(client, jsonSerializer, executionContext), IReferenceDataAgent
{
/// <summary>
/// Initializes a new instance of the <see cref="ReferenceDataAgent"/> class.
/// </summary>
/// <param name="client">The underlying <see cref="HttpClient"/>.</param>
/// <param name="jsonSerializer">The optional <see cref="IJsonSerializer"/>.</param>
/// <param name="executionContext">The optional <see cref="CoreEx.ExecutionContext"/>.</param>
public ReferenceDataAgent(HttpClient client, IJsonSerializer? jsonSerializer = null, CoreEx.ExecutionContext? executionContext = null) : base(client, jsonSerializer, executionContext) { }

/// <inheritdoc/>
public Task<HttpResult<RefDataNamespace.OpenStatusCollection>> OpenStatusGetAllAsync(ReferenceDataFilter? args = null, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync<RefDataNamespace.OpenStatusCollection>("api/v1/ref/openstatuses", requestOptions: requestOptions, args: HttpArgs.Create(new HttpArg<ReferenceDataFilter>("args", args!, HttpArgType.FromUriUseProperties)), cancellationToken);
=> GetAsync<RefDataNamespace.OpenStatusCollection>("api/v1/ref/openstatuses", requestOptions, [new HttpArg<ReferenceDataFilter?>("args", args, HttpArgType.FromUriUseProperties)], cancellationToken);

/// <inheritdoc/>
public Task<HttpResult<RefDataNamespace.ProductCategoryCollection>> ProductCategoryGetAllAsync(ReferenceDataFilter? args = null, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync<RefDataNamespace.ProductCategoryCollection>("api/v1/ref/productcategories", requestOptions: requestOptions, args: HttpArgs.Create(new HttpArg<ReferenceDataFilter>("args", args!, HttpArgType.FromUriUseProperties)), cancellationToken);
=> GetAsync<RefDataNamespace.ProductCategoryCollection>("api/v1/ref/productcategories", requestOptions, [new HttpArg<ReferenceDataFilter?>("args", args, HttpArgType.FromUriUseProperties)], cancellationToken);

/// <inheritdoc/>
public Task<HttpResult<RefDataNamespace.AccountUTypeCollection>> AccountUTypeGetAllAsync(ReferenceDataFilter? args = null, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync<RefDataNamespace.AccountUTypeCollection>("api/v1/ref/accountutypes", requestOptions: requestOptions, args: HttpArgs.Create(new HttpArg<ReferenceDataFilter>("args", args!, HttpArgType.FromUriUseProperties)), cancellationToken);
=> GetAsync<RefDataNamespace.AccountUTypeCollection>("api/v1/ref/accountutypes", requestOptions, [new HttpArg<ReferenceDataFilter?>("args", args, HttpArgType.FromUriUseProperties)], cancellationToken);

/// <inheritdoc/>
public Task<HttpResult<RefDataNamespace.MaturityInstructionsCollection>> MaturityInstructionsGetAllAsync(ReferenceDataFilter? args = null, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync<RefDataNamespace.MaturityInstructionsCollection>("api/v1/ref/maturityinstructions", requestOptions: requestOptions, args: HttpArgs.Create(new HttpArg<ReferenceDataFilter>("args", args!, HttpArgType.FromUriUseProperties)), cancellationToken);
=> GetAsync<RefDataNamespace.MaturityInstructionsCollection>("api/v1/ref/maturityinstructions", requestOptions, [new HttpArg<ReferenceDataFilter?>("args", args, HttpArgType.FromUriUseProperties)], cancellationToken);

/// <inheritdoc/>
public Task<HttpResult<RefDataNamespace.TransactionTypeCollection>> TransactionTypeGetAllAsync(ReferenceDataFilter? args = null, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync<RefDataNamespace.TransactionTypeCollection>("api/v1/ref/transactiontypes", requestOptions: requestOptions, args: HttpArgs.Create(new HttpArg<ReferenceDataFilter>("args", args!, HttpArgType.FromUriUseProperties)), cancellationToken);
=> GetAsync<RefDataNamespace.TransactionTypeCollection>("api/v1/ref/transactiontypes", requestOptions, [new HttpArg<ReferenceDataFilter?>("args", args, HttpArgType.FromUriUseProperties)], cancellationToken);

/// <inheritdoc/>
public Task<HttpResult<RefDataNamespace.TransactionStatusCollection>> TransactionStatusGetAllAsync(ReferenceDataFilter? args = null, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync<RefDataNamespace.TransactionStatusCollection>("api/v1/ref/transactionstatuses", requestOptions: requestOptions, args: HttpArgs.Create(new HttpArg<ReferenceDataFilter>("args", args!, HttpArgType.FromUriUseProperties)), cancellationToken);
=> GetAsync<RefDataNamespace.TransactionStatusCollection>("api/v1/ref/transactionstatuses", requestOptions, [new HttpArg<ReferenceDataFilter?>("args", args, HttpArgType.FromUriUseProperties)], cancellationToken);

/// <inheritdoc/>
public Task<HttpResult> GetNamedAsync(string[] names, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ namespace Cdr.Banking.Common.Agents;
/// <summary>
/// Provides the <see cref="Transaction"/> HTTP agent.
/// </summary>
public partial class TransactionAgent : TypedHttpClientBase<TransactionAgent>, ITransactionAgent
/// <param name="client">The underlying <see cref="HttpClient"/>.</param>
/// <param name="jsonSerializer">The optional <see cref="IJsonSerializer"/>.</param>
/// <param name="executionContext">The optional <see cref="CoreEx.ExecutionContext"/>.</param>
public partial class TransactionAgent(HttpClient client, IJsonSerializer? jsonSerializer = null, CoreEx.ExecutionContext? executionContext = null) : TypedHttpClientBase<TransactionAgent>(client, jsonSerializer, executionContext), ITransactionAgent
{
/// <summary>
/// Initializes a new instance of the <see cref="TransactionAgent"/> class.
/// </summary>
/// <param name="client">The underlying <see cref="HttpClient"/>.</param>
/// <param name="jsonSerializer">The optional <see cref="IJsonSerializer"/>.</param>
/// <param name="executionContext">The optional <see cref="CoreEx.ExecutionContext"/>.</param>
public TransactionAgent(HttpClient client, IJsonSerializer? jsonSerializer = null, CoreEx.ExecutionContext? executionContext = null) : base(client, jsonSerializer, executionContext) { }

/// <inheritdoc/>
public Task<HttpResult<TransactionCollectionResult>> GetTransactionsAsync(string? accountId, TransactionArgs? args, PagingArgs? paging = null, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync<TransactionCollectionResult>("api/v1/banking/accounts/{accountId}/transactions", requestOptions: requestOptions.IncludePaging(paging), args: HttpArgs.Create(new HttpArg<string?>("accountId", accountId), new HttpArg<TransactionArgs?>("args", args, HttpArgType.FromUriUseProperties)), cancellationToken: cancellationToken);
=> GetAsync<TransactionCollectionResult>("api/v1/banking/accounts/{accountId}/transactions", requestOptions.IncludePaging(paging), [new HttpArg<string?>("accountId", accountId), new HttpArg<TransactionArgs?>("args", args, HttpArgType.FromUriUseProperties)], cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<Folder Include="Entities\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CoreEx" Version="3.27.2" />
<PackageReference Include="CoreEx" Version="3.27.3" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="CoreEx.UnitTesting.NUnit" Version="3.27.2" />
<PackageReference Include="CoreEx.UnitTesting.NUnit" Version="3.27.3" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/Demo/Beef.Demo.Api/Beef.Demo.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CoreEx.AspNetCore" Version="3.27.2" />
<PackageReference Include="CoreEx.AspNetCore" Version="3.27.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.9.0" />
</ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions samples/Demo/Beef.Demo.Business/Beef.Demo.Business.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CoreEx" Version="3.27.2" />
<PackageReference Include="CoreEx.AspNetCore" Version="3.27.2" />
<PackageReference Include="CoreEx.Cosmos" Version="3.27.2" />
<PackageReference Include="CoreEx.Database" Version="3.27.2" />
<PackageReference Include="CoreEx.Database.SqlServer" Version="3.27.2" />
<PackageReference Include="CoreEx.EntityFrameworkCore" Version="3.27.2" />
<PackageReference Include="CoreEx.Validation" Version="3.27.2" />
<PackageReference Include="CoreEx.FluentValidation" Version="3.27.2" />
<PackageReference Include="CoreEx" Version="3.27.3" />
<PackageReference Include="CoreEx.AspNetCore" Version="3.27.3" />
<PackageReference Include="CoreEx.Cosmos" Version="3.27.3" />
<PackageReference Include="CoreEx.Database" Version="3.27.3" />
<PackageReference Include="CoreEx.Database.SqlServer" Version="3.27.3" />
<PackageReference Include="CoreEx.EntityFrameworkCore" Version="3.27.3" />
<PackageReference Include="CoreEx.Validation" Version="3.27.3" />
<PackageReference Include="CoreEx.FluentValidation" Version="3.27.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.20" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions samples/Demo/Beef.Demo.Business/Data/PersonData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private async Task<Person> MergeOnImplementationAsync(Guid personFromId, Guid pe
private Task MarkOnImplementationAsync()
{
using var scope = _logger.BeginScope(new Dictionary<string, object> { { "MyKey", "MyValue" } });
CoreEx.ExecutionContext.Current.Messages.Add(MessageType.Warning, "Software licence is overdue; please pay immediately or services will be halted.");
_logger.LogWarning("Mark operation implementation currently does not exist.");
return Task.CompletedTask;
}
Expand Down
13 changes: 4 additions & 9 deletions samples/Demo/Beef.Demo.Common/Agents/Generated/ConfigAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ namespace Beef.Demo.Common.Agents;
/// <summary>
/// Provides the <b>Config</b> HTTP agent.
/// </summary>
public partial class ConfigAgent : TypedHttpClientBase<ConfigAgent>, IConfigAgent
/// <param name="client">The underlying <see cref="HttpClient"/>.</param>
/// <param name="jsonSerializer">The optional <see cref="IJsonSerializer"/>.</param>
/// <param name="executionContext">The optional <see cref="CoreEx.ExecutionContext"/>.</param>
public partial class ConfigAgent(HttpClient client, IJsonSerializer? jsonSerializer = null, CoreEx.ExecutionContext? executionContext = null) : TypedHttpClientBase<ConfigAgent>(client, jsonSerializer, executionContext), IConfigAgent
{
/// <summary>
/// Initializes a new instance of the <see cref="ConfigAgent"/> class.
/// </summary>
/// <param name="client">The underlying <see cref="HttpClient"/>.</param>
/// <param name="jsonSerializer">The optional <see cref="IJsonSerializer"/>.</param>
/// <param name="executionContext">The optional <see cref="CoreEx.ExecutionContext"/>.</param>
public ConfigAgent(HttpClient client, IJsonSerializer? jsonSerializer = null, CoreEx.ExecutionContext? executionContext = null) : base(client, jsonSerializer, executionContext) { }

/// <inheritdoc/>
public Task<HttpResult<System.Collections.IDictionary>> GetEnvVarsAsync(HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> PostAsync<System.Collections.IDictionary>("api/v1/envvars", requestOptions: requestOptions, cancellationToken: cancellationToken);
Expand Down
Loading

0 comments on commit 1ee170a

Please sign in to comment.