Skip to content

Commit

Permalink
✨ Add Aspire SQL Server integration
Browse files Browse the repository at this point in the history
✨ Update template options
✨ Update NSwag
  • Loading branch information
jasontaylordev committed Nov 21, 2024
1 parent aa31bf1 commit d1bfdca
Show file tree
Hide file tree
Showing 29 changed files with 2,598 additions and 678 deletions.
5 changes: 3 additions & 2 deletions .template.config/dotnetcli.host.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"longName": "pipeline-provider",
"shortName": "pp"
},
"UseSQLite": {
"longName": "use-sqlite"
"Database": {
"longName": "database",
"shortName": "db"
},
"UseAspire": {
"longName": "use-aspire"
Expand Down
12 changes: 6 additions & 6 deletions .template.config/ide.host.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
"isVisible": true
},
{
"id": "UseSQLite",
"id": "PipelineProvider",
"name": {
"text": "Use SQLite"
"text": "Pipeline Provider"
},
"description": {
"text": "Use SQLite for database (default is LocalDB)."
"text": "Select the pipeline provider."
},
"isVisible": true
},
{
"id": "PipelineProvider",
"id": "Database",
"name": {
"text": "Pipeline Provider"
"text": "Database"
},
"description": {
"text": "Select the pipeline provider."
"text": "Select the database type."
},
"isVisible": true
},
Expand Down
37 changes: 26 additions & 11 deletions .template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"$schema": "http://json.schemastore.org/template",
"author": "JasonTaylorDev",
"classifications": [
"Aspire",
"Web",
"SPA",
"ASP.NET",
Expand Down Expand Up @@ -50,18 +51,28 @@
"type": "computed",
"value": "(ClientFramework == \"None\")"
},
"UseSQLite": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Whether to use SQLite instead of LocalDB."
},
"UseAspire": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Use .NET Aspire"
},
"Database": {
"type": "parameter",
"datatype": "choice",
"choices": [
{
"choice": "sqlite",
"description": "SQLite. This option only applies if --aspire is not specified."
},
{
"choice": "sqlserver",
"description": "SQL Server."
}
],
"defaultValue": "sqlserver",
"description": "The database type to use."
},
"PipelineProvider": {
"type": "parameter",
"datatype": "choice",
Expand All @@ -86,9 +97,13 @@
"type": "computed",
"value": "(PipelineProvider == \"github\")"
},
"UseLocalDB": {
"UseSqlite": {
"type": "computed",
"value": "(Database == \"sqlite\")"
},
"UseSqlServer": {
"type": "computed",
"value": "(!UseSQLite)"
"value": "(Database == \"sqlserver\")"
},
"caRepositoryUrl": {
"type": "generated",
Expand All @@ -103,7 +118,7 @@
"generator": "constant",
"replaces": "caPackageVersion",
"parameters": {
"value": "9.0.1"
"value": "9.0.2"
}
}
},
Expand Down Expand Up @@ -178,15 +193,15 @@
]
},
{
"condition": "(UseLocalDB)",
"condition": "(UseSqlServer)",
"exclude": [
"src/Infrastructure/Data/SQLite/**",
"src/Web/appsettings.SQLite.json",
"tests/Application.FunctionalTests/SqliteTestDatabase.cs"
]
},
{
"condition": "(UseSQLite)",
"condition": "(UseSqlite)",
"exclude": [
"src/Infrastructure/Data/Migrations/**",
"src/Web/appsettings.json",
Expand Down
7 changes: 3 additions & 4 deletions CleanArchitecture.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
<metadata>

<id>Clean.Architecture.Solution.Template</id>
<version>9.0.1</version>
<version>9.0.2</version>
<title>Clean Architecture Solution Template</title>
<authors>JasonTaylorDev</authors>
<description>Clean Architecture Solution Template for .NET 9.</description>
<summary>
A Clean Architecture Solution Template for creating apps using Angular, React, or Web API only with ASP.NET Core.
</summary>
<releaseNotes>
📦 Upgrade to Angular 18
🐛 Miscellaneous bug fixes
📦 Add Aspire
</releaseNotes>

<projectUrl>https://github.com/JasonTaylorDev/CleanArchitecture</projectUrl>
<repository type="git" url="https://github.com/JasonTaylorDev/CleanArchitecture.git" branch="main" />

<license type="expression">MIT</license>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<tags>clean-architecture project template csharp dotnet angular react</tags>
<tags>clean-architecture project template csharp dotnet angular react aspire</tags>
<icon>icon.png</icon>
<readme>README.md</readme>

Expand Down
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<WarningsNotAsErrors>NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>
<!-- <ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath> -->
<ImplicitUsings>enable</ImplicitUsings>
<DefineConstants>UseAspire</DefineConstants>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
16 changes: 10 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
<MicrosoftExtensionsVersion>9.0.0</MicrosoftExtensionsVersion>
</PropertyGroup>
<ItemGroup>
<!-- Begin Aspire -->
<!--#if (UseAspire)-->
<!--#if (UseSqlServer)-->
<PackageVersion Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageVersion Include="Aspire.Hosting.SqlServer" Version="9.0.0" />
<!--#endif-->
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0" />
Expand All @@ -16,7 +20,7 @@
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
<!-- End Aspire -->
<!--#endif-->
<PackageVersion Include="Ardalis.GuardClauses" Version="4.6.0" />
<PackageVersion Include="AutoMapper" Version="13.0.1" />
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.2" />
Expand All @@ -38,10 +42,10 @@
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="$(EfcoreVersion)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="$(EfcoreVersion)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="$(EfcoreVersion)" />
<!--#if (UseSQLite)-->
<!--#if (UseSqlite)-->
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="$(EfcoreVersion)" />
<!--#endif-->
<!--#if (UseLocalDB)-->
<!--#if (UseSqlServer)-->
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EfcoreVersion)" />
<!--#endif-->
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="$(EfcoreVersion)" />
Expand All @@ -51,8 +55,8 @@
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="NSwag.AspNetCore" Version="14.1.0" />
<PackageVersion Include="NSwag.MSBuild" Version="14.1.0" />
<PackageVersion Include="NSwag.AspNetCore" Version="14.2.0" />
<PackageVersion Include="NSwag.MSBuild" Version="14.2.0" />
<PackageVersion Include="nunit" Version="3.14.0" />
<PackageVersion Include="NUnit.Analyzers" Version="3.10.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The following prerequisites are required to build and run the solution:

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::9.0.1
dotnet new install Clean.Architecture.Solution.Template::9.0.2
```

Once installed, create a new solution using the template. You can choose to use Angular, React, or create a Web API-only solution. Specify the client framework using the `-cf` or `--client-framework` option, and provide the output directory where your project will be created. Here are some examples:
Expand Down Expand Up @@ -69,10 +69,10 @@ dotnet new ca-usecase --help

## Database

The template is configured to use SQL Server by default. If you would prefer to use SQLite, create your solution using the following command:
The templates supports both SQL Server (default) and SQLite. Specify the database to use with the `--database` option:

```bash
dotnet new ca-sln --use-sqlite
dotnet new ca-sln --database [sqlite|sqlserver]
```

When you run the application the database will be automatically created (if necessary) and the latest migrations will be applied.
Expand Down
2 changes: 1 addition & 1 deletion infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module database 'core/database/sqlserver.bicep' = {
tags: tags
databaseName: !empty(sqlDatabaseName) ? sqlDatabaseName : '${abbrs.sqlServersDatabases}${resourceToken}'
keyVaultName: keyVault.outputs.name
connectionStringKey: 'ConnectionStrings--DefaultConnection'
connectionStringKey: 'ConnectionStrings--CleanArchitectureDb'
sqlAdminPassword: sqlAdminPassword
appUserPassword: appUserPassword
}
Expand Down
3 changes: 3 additions & 0 deletions src/AppHost/AppHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
<!--#if (UseSqlServer)-->
<PackageReference Include="Aspire.Hosting.SqlServer" />
<!--#endif-->
</ItemGroup>

<ItemGroup>
Expand Down
11 changes: 10 additions & 1 deletion src/AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject<Projects.Web>("web");
// Note: To run without Docker, simply remove sql and database:
// builder.AddProject<Projects.Web>("web");

var sql = builder.AddSqlServer("sql");

var database = sql.AddDatabase("CleanArchitectureDb");

builder.AddProject<Projects.Web>("web")
.WaitFor(database)
.WithReference(database);

builder.Build().Run();
Loading

0 comments on commit d1bfdca

Please sign in to comment.