Added api project boilerplate

This commit is contained in:
quentin 2024-04-16 18:38:11 -05:00
parent 37536443d3
commit 0b2c77d4cc
5 changed files with 121 additions and 0 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
/DAL/bin/
/DAL/obj/
/API/bin/
/API/obj/
/API/appsettings.*

24
API/API.csproj Normal file
View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0-preview.3.24172.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Authentication\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DAL\DAL.csproj" />
</ItemGroup>
</Project>

47
API/Program.cs Normal file
View File

@ -0,0 +1,47 @@
using DAL.Contexts;
using Microsoft.EntityFrameworkCore;
using System.Reflection;
using InvalidOperationException = System.InvalidOperationException;
namespace API
{
internal class Program
{
public static void Main(string[] args)
{
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
ConfigurationManager configManager = builder.Configuration;
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
string xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
string xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
options.IncludeXmlComments(xmlPath, true);
});
builder.Services.AddDbContext<SASGContext>(options =>
{
options.UseMySQL(builder.Configuration["connectionString"] ?? throw new InvalidOperationException("Connection String is null"));
});
WebApplication app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseCookiePolicy(new CookiePolicyOptions
{
MinimumSameSitePolicy = SameSiteMode.Strict
});
app.UseHttpsRedirection();
app.MapControllers();
app.Run();
}
}
}

View File

@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:36321",
"sslPort": 44359
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5279",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7089;http://localhost:5279",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL", "DAL\DAL.csproj", "{EE2CF24D-1C19-4915-A6BB-7A244F527CE4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -12,5 +14,9 @@ Global
{EE2CF24D-1C19-4915-A6BB-7A244F527CE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE2CF24D-1C19-4915-A6BB-7A244F527CE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE2CF24D-1C19-4915-A6BB-7A244F527CE4}.Release|Any CPU.Build.0 = Release|Any CPU
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{829DACCE-0D9E-43C8-A8C1-692C9FF6804A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal