diff --git a/.template.config/dotnetcli.host.json b/.template.config/dotnetcli.host.json
index 5661484..e812939 100644
--- a/.template.config/dotnetcli.host.json
+++ b/.template.config/dotnetcli.host.json
@@ -3,6 +3,10 @@
"GitHost": {
"longName": "git-host",
"shortName": "gh"
+ },
+ "Database": {
+ "longName": "database",
+ "shortName": "db"
}
}
}
diff --git a/.template.config/ide.host.json b/.template.config/ide.host.json
index 1183c66..298d3b2 100644
--- a/.template.config/ide.host.json
+++ b/.template.config/ide.host.json
@@ -12,6 +12,16 @@
"text": "Select the git respository host"
},
"isVisible": true
+ },
+ {
+ "id": "Database",
+ "name": {
+ "text": "Database"
+ },
+ "description": {
+ "text": "Select the database"
+ },
+ "isVisible": true
}
]
}
diff --git a/.template.config/template.json b/.template.config/template.json
index e8d9709..35a616e 100644
--- a/.template.config/template.json
+++ b/.template.config/template.json
@@ -42,6 +42,38 @@
"UseNoGitHost": {
"type": "computed",
"value": "(GitHost == \"None\")"
+ },
+ "Database": {
+ "type": "parameter",
+ "datatype": "choice",
+ "choices": [
+ {
+ "choice": "MSSql",
+ "description": "Use Microsoft SQL or Azure SQL"
+ },
+ {
+ "choice": "PostgreSql",
+ "description": "Use PostgreSql"
+ },
+ {
+ "choice": "None",
+ "description": ""
+ }
+ ],
+ "defaultValue": "None",
+ "description": "The type of database to use"
+ },
+ "UseMSSql": {
+ "type": "computed",
+ "value": "(Database == \"MSSql\")"
+ },
+ "UsePostgreSql": {
+ "type": "computed",
+ "value": "(Database == \"PostgreSql\")"
+ },
+ "UseDatabase": {
+ "type": "computed",
+ "value": "(Database != \"None\")"
}
},
"sources": [
@@ -60,6 +92,12 @@
{
"condition": "(UseNoGitHost)",
"exclude": [".azuredevops/**", ".github/**"]
+ },
+ {
+ "condition": "(!UseDatabase)",
+ "exclude": [
+ "src/Application/Infrastructure/Persistance/**"
+ ]
}
]
}
diff --git a/README.md b/README.md
index 29be9b2..f67d31e 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,7 @@ dotnet new vsma --name ProjectName
```
dotnet new vsma --name [ProjectName]
[-gh|--git-host [Github|AzureDevOps|None]]
+ [-db|--database [MsSql|PostgreSql|None]]
```
### Options
@@ -35,6 +36,8 @@ dotnet new vsma --name [ProjectName]
* `-gh|--git-host [Github|AzureDevOps|None]`
Choose the platform you will host your projects git repository, this will give you a base CI workflow, pull request template, and anything specific to the platform that might be of use. The default value is `None`.
+* `-db|--database [MsSql|PostgreSql|None]`
+ Choose what database to use for your project. The default is `None`
## How to Run
diff --git a/src/Api/Api.csproj b/src/Api/Api.csproj
index be1a247..d0110c7 100644
--- a/src/Api/Api.csproj
+++ b/src/Api/Api.csproj
@@ -15,16 +15,19 @@
-
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
+
+
diff --git a/src/Application/Application.csproj b/src/Application/Application.csproj
index da05a82..063add8 100644
--- a/src/Application/Application.csproj
+++ b/src/Application/Application.csproj
@@ -1,4 +1,4 @@
-
+
net7.0
@@ -10,10 +10,18 @@
+
+
+
+
+
+
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
@@ -24,15 +32,17 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
-
-
-
-
-
-
+
+
+
+
-
+
+
+
+
+
+
diff --git a/src/Application/Infrastructure/ConfigureServices.cs b/src/Application/Infrastructure/ConfigureServices.cs
index 84d08a0..71262b1 100644
--- a/src/Application/Infrastructure/ConfigureServices.cs
+++ b/src/Application/Infrastructure/ConfigureServices.cs
@@ -1,10 +1,14 @@
using Application.Common.Interfaces;
+#if UseDatabase
using Application.Infrastructure.Persistance;
using Application.Infrastructure.Persistance.Interceptors;
-using Application.Infrastructure.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
+
+#endif
+using Application.Infrastructure.Services;
+
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -14,6 +18,9 @@ public static class ConfigureInfrastructureServices
{
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
{
+ services.AddTransient();
+
+#if UseDatabase
services.AddScoped();
services.AddScoped();
services.AddScoped();
@@ -22,15 +29,18 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti
{
options.AddInterceptors(sp.GetServices());
+#if UseMSSql
options.UseSqlServer(configuration.GetConnectionString("Default"),
builder => builder.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName));
+#elif UsePostgreSql
+ options.UseNpgsql(configuration.GetConnectionString("Default"),
+ builder => builder.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName));
+#endif
});
- services.AddTransient();
-
services.AddHealthChecks()
.AddDbContextCheck("Database");
-
+#endif
return services;
}