diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bb8d03e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +**/obj +**/bin +appsettings.*.json \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..cb403d8 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,32 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/net8.0/BasicDotnetTemplate.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_URLS": "https://localhost:5000;https://localhost:5001", + "ASPNETCORE_DETAILEDERRORS": "1", + "ASPNETCORE_SHUTDOWNTIMEOUTSECONDS": "3" + } + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..1970917 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/BasicDotnetTemplate.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/BasicDotnetTemplate.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/BasicDotnetTemplate.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/BasicDotnetTemplate.csproj b/BasicDotnetTemplate.csproj new file mode 100644 index 0000000..85de4cc --- /dev/null +++ b/BasicDotnetTemplate.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + + + + + + + diff --git a/Models/Settings/Settings.cs b/Models/Settings/Settings.cs new file mode 100644 index 0000000..c389e4b --- /dev/null +++ b/Models/Settings/Settings.cs @@ -0,0 +1,10 @@ +namespace BasicDotnetTemplate.Models.Settings; + +public class Settings +{ +#nullable enable + public string? Name { get; set; } + public string? Version { get; set; } + public string? Description { get; set; } +#nullable disable +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..e99ea7b --- /dev/null +++ b/Program.cs @@ -0,0 +1,81 @@ +using Microsoft.OpenApi.Models; +using BasicDotnetTemplate.Models.Settings; + +namespace BasicDotnetTemplate; +internal class Program +{ + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + var _configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true) + .AddEnvironmentVariables() + .Build(); + + // REGISTER SERVICES HERE + builder.Services.AddSingleton(_configuration); + + builder.Services.Configure(_configuration.GetSection("Settings")); + + builder.Services.AddAuthentication(); + builder.Services.AddAuthorization(); + + builder.Services.AddControllers(); + + builder.Services.AddEndpointsApiExplorer(); + + Settings settings = new Settings(); + _configuration.GetSection("Settings").Bind(settings); + + builder.Services.AddSwaggerGen(options => + { + options.SwaggerDoc("v1", new OpenApiInfo + { + Version = settings.Version, + Title = settings.Name, + Description = settings.Description, + TermsOfService = new Uri("https://example.com/terms"), + Contact = new OpenApiContact + { + Name = "Example Contact", + Url = new Uri("https://example.com/contact") + }, + License = new OpenApiLicense + { + Name = "Example License", + Url = new Uri("https://example.com/license") + } + }); + }); + + // Register IConfiguration in the service container + + + var app = builder.Build(); + + // REGISTER MIDDLEWARE HERE + app.UseAuthentication(); + app.UseAuthorization(); + + app.MapGet("/", () => + { + return "Hello World!"; + }); + + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(options => + { + options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); + options.RoutePrefix = string.Empty; + }); + } + + app.Run(); + } + +} \ No newline at end of file diff --git a/README.md b/README.md index 7dcec64..8485399 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# basic_dotnet_template \ No newline at end of file +# BasicDotnetTemplate + + diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..fb4fb5b --- /dev/null +++ b/appsettings.json @@ -0,0 +1,7 @@ +{ + "Settings": { + "Name": "BasicDotnetTemplate", + "Version": "v1.0", + "Description": "This template contains basic configuration for a .Net 8 backend" + } +} \ No newline at end of file