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

✨ Add use case templates (commands and queries) #881

Merged
merged 5 commits into from
Jun 29, 2023
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
1 change: 1 addition & 0 deletions .template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"**/[Bb]in/**",
"**/[Oo]bj/**",
".template.config/**/*",
"templates/**/*",
".vs/**/*",
"**/*.filelist",
"**/*.user",
Expand Down
4 changes: 2 additions & 2 deletions CleanArchitecture.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<metadata>

<id>Clean.Architecture.Solution.Template</id>
<version>8.0.0-preview.5.1</version>
<version>8.0.0-preview.5.2</version>
<title>Clean Architecture Solution Template</title>
<authors>JasonTaylorDev</authors>
<description>Clean Architecture Solution Template for .NET 8.</description>
<summary>
A Clean Architecture Solution Template for creating a Single-Page Application (SPA) with ASP.NET Core.
</summary>
<releaseNotes>
Added support for React.
Added item template for creating use cases (commands and queries)
</releaseNotes>

<projectUrl>https://github.com/JasonTaylorDev/CleanArchitecture</projectUrl>
Expand Down
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,39 @@ The goal of this template is to provide a straightforward and efficient approach
* [FluentValidation](https://fluentvalidation.net/)
* [NUnit](https://nunit.org/), [FluentAssertions](https://fluentassertions.com/), [Moq](https://github.com/moq) & [Respawn](https://github.com/jbogard/Respawn)

## Dependencies
The template depends on the latest versions of:

* [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0)
* [Node.js LTS](https://nodejs.org/en/)

## Getting Started

The easiest way to get started is to install the [.NET template](https://www.nuget.org/packages/Clean.Architecture.Solution.Template) and run `dotnet new ca-sln`:
The easiest way to get started is to install the [.NET template](https://www.nuget.org/packages/Clean.Architecture.Solution.Template):
```
dotnet new install Clean.Architecture.Solution.Template::8.0.0-preview.5.2
````

Once installed, create a new solution using the template:
```
dotnet new ca-sln -c <Angular|React> --output <YourProjectName>
```

1. Install the latest versions of [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) and [Node.js LTS](https://nodejs.org/en/)
2. Run `dotnet new install Clean.Architecture.Solution.Template::8.0.0-preview.5.1` to install the .NET template
4. Run `dotnet new ca-sln -c <Angular|React> --output <YourProjectName>` to create a new project
5. Navigate to `YourProjectName/src/WebUI` and launch the project using `dotnet run`
The above command creates a SPA with Angular or React on ASP.NET Core. Start the application by navigating to `./src/WebUI` and running:
```
dotnet run
```

Create use cases (commands or queries) by navigating to `./src/Application`, and running:
```
dotnet new ca-usecase --feature TodoLists --name CreateTodoList --useCaseType command --returnType int
```

To learn more, run the following command:

```
dotnet new ca-usecase --help
```

## Database

Expand Down
Binary file added templates/ca-use-case/.template.config/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions templates/ca-use-case/.template.config/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "JasonTaylorDev",
"classifications": [
"Clean Architecture"
],
"name": "Clean Architecture Solution Use Case",
"description": "Create a new use case (query or command)",
"identity": "Clean.Architecture.Solution.UseCase.CSharp",
"groupIdentity": "Clean.Architecture.Solution.UseCase",
"shortName": "ca-usecase",
"tags": {
"language": "C#",
"type": "item"
},
"sourceName": "CleanArchitectureUseCase",
"preferNameDirectory": false,
"symbols": {
"DefaultNamespace": {
"type": "bind",
"binding": "msbuild:RootNamespace",
"replaces": "CleanArchitecture.Application",
"defaultValue": "CleanArchitecture.Application"
},
"featureName": {
"type": "parameter",
"datatype": "string",
"isRequired": true,
"replaces": "FeatureName",
"fileRename": "FeatureName"
},
"useCaseType": {
"type": "parameter",
"datatype": "choice",
"isRequired": true,
"choices": [
{
"choice": "command",
"description": "Create a new command"
},
{
"choice": "query",
"description": "Create a new query"
}
],
"description": "The type of use case to create"
},
"createCommand": {
"type": "computed",
"value": "(useCaseType == \"command\")"
},
"createQuery": {
"type": "computed",
"value": "(useCaseType == \"query\")"
},
"returnType": {
"type": "parameter",
"datatype": "string",
"isRequired": false,
"replaces": "object",
"defaultValue": "object"
}
},
"sources": [
{
"modifiers": [
{
"condition": "(createCommand)",
"exclude": [ "FeatureName/Queries/**/*" ]
},
{
"condition": "(createQuery)",
"exclude": [ "FeatureName/Commands/**/*" ]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using CleanArchitecture.Application.Common.Interfaces;

namespace CleanArchitecture.Application.FeatureName.Commands.CleanArchitectureUseCase;

public record CleanArchitectureUseCaseCommand : IRequest<object>
{
}

public class CleanArchitectureUseCaseCommandValidator : AbstractValidator<CleanArchitectureUseCaseCommand>
{
public CleanArchitectureUseCaseCommandValidator()
{
}
}

public class CleanArchitectureUseCaseCommandHandler : IRequestHandler<CleanArchitectureUseCaseCommand, object>
{
private readonly IApplicationDbContext _context;

public CleanArchitectureUseCaseCommandHandler(IApplicationDbContext context)
{
_context = context;
}

public async Task<object> Handle(CleanArchitectureUseCaseCommand request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using CleanArchitecture.Application.Common.Interfaces;

namespace CleanArchitecture.Application.FeatureName.Queries.CleanArchitectureUseCase;

public record CleanArchitectureUseCaseQuery : IRequest<object>
{
}

public class CleanArchitectureCommandCommandValidator : AbstractValidator<CleanArchitectureCommandCommand>
{
public CleanArchitectureCommandCommandValidator()
{
}
}

public class CleanArchitectureUseCaseQueryHandler : IRequestHandler<CleanArchitectureUseCaseQuery, object>
{
private readonly IApplicationDbContext _context;

public CleanArchitectureUseCaseQueryHandler(IApplicationDbContext context)
{
_context = context;
}

public async Task<object> Handle(CleanArchitectureUseCaseQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}