Skip to content
Open
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
57 changes: 57 additions & 0 deletions SampleWebApp.Core.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9FF20346-3D13-434F-83A3-1AED2595A4C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataLayer", "src\DataLayer\DataLayer.csproj", "{95183941-219F-4EBC-8166-E5A004418ED8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizLayer", "src\BizLayer\BizLayer.csproj", "{B076027A-3826-4706-8DC2-1170C9DA685F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceLayer", "src\ServiceLayer\ServiceLayer.csproj", "{E8A094CF-B6F3-4F7A-846A-677C1D542A71}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApp", "src\SampleWebApp\SampleWebApp.csproj", "{D7345466-1A7E-4805-A2B8-45E1C76C9528}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CA425ABC-E141-41ED-9969-A42EF32A6D35}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "tests\Tests\Tests.csproj", "{B66678CE-F90E-4426-9D5D-2B86EBB14EBB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{95183941-219F-4EBC-8166-E5A004418ED8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95183941-219F-4EBC-8166-E5A004418ED8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95183941-219F-4EBC-8166-E5A004418ED8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95183941-219F-4EBC-8166-E5A004418ED8}.Release|Any CPU.Build.0 = Release|Any CPU
{B076027A-3826-4706-8DC2-1170C9DA685F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B076027A-3826-4706-8DC2-1170C9DA685F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B076027A-3826-4706-8DC2-1170C9DA685F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B076027A-3826-4706-8DC2-1170C9DA685F}.Release|Any CPU.Build.0 = Release|Any CPU
{E8A094CF-B6F3-4F7A-846A-677C1D542A71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8A094CF-B6F3-4F7A-846A-677C1D542A71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8A094CF-B6F3-4F7A-846A-677C1D542A71}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8A094CF-B6F3-4F7A-846A-677C1D542A71}.Release|Any CPU.Build.0 = Release|Any CPU
{D7345466-1A7E-4805-A2B8-45E1C76C9528}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7345466-1A7E-4805-A2B8-45E1C76C9528}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7345466-1A7E-4805-A2B8-45E1C76C9528}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7345466-1A7E-4805-A2B8-45E1C76C9528}.Release|Any CPU.Build.0 = Release|Any CPU
{B66678CE-F90E-4426-9D5D-2B86EBB14EBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B66678CE-F90E-4426-9D5D-2B86EBB14EBB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B66678CE-F90E-4426-9D5D-2B86EBB14EBB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B66678CE-F90E-4426-9D5D-2B86EBB14EBB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{95183941-219F-4EBC-8166-E5A004418ED8} = {9FF20346-3D13-434F-83A3-1AED2595A4C2}
{B076027A-3826-4706-8DC2-1170C9DA685F} = {9FF20346-3D13-434F-83A3-1AED2595A4C2}
{E8A094CF-B6F3-4F7A-846A-677C1D542A71} = {9FF20346-3D13-434F-83A3-1AED2595A4C2}
{D7345466-1A7E-4805-A2B8-45E1C76C9528} = {9FF20346-3D13-434F-83A3-1AED2595A4C2}
{B66678CE-F90E-4426-9D5D-2B86EBB14EBB} = {CA425ABC-E141-41ED-9969-A42EF32A6D35}
EndGlobalSection
EndGlobal
13 changes: 13 additions & 0 deletions src/BizLayer/BizLayer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\DataLayer\DataLayer.csproj" />
</ItemGroup>

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
15 changes: 15 additions & 0 deletions src/BizLayer/Startup/BizLayerServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Extensions.DependencyInjection;

namespace BizLayer.Startup;

/// <summary>
/// Registers business-layer dependencies with the application's DI container.
/// Concrete business logic is added in later migration phases.
/// </summary>
public static class BizLayerServiceExtensions
{
public static IServiceCollection AddBizLayer(this IServiceCollection services)
{
return services;
}
}
22 changes: 22 additions & 0 deletions src/DataLayer/DataClasses/SampleWebAppDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;

namespace DataLayer.DataClasses;

/// <summary>
/// EF Core replacement for the legacy EF6 <c>SampleWebAppDb</c>.
/// Entity sets (Blogs, Posts, Tags) will be added in subsequent migration phases.
/// </summary>
public class SampleWebAppDbContext : DbContext
{
public const string ConnectionStringName = "SampleWebAppDb";

public SampleWebAppDbContext(DbContextOptions<SampleWebAppDbContext> options)
: base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
18 changes: 18 additions & 0 deletions src/DataLayer/DataLayer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.36" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.36" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.36">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions src/DataLayer/Startup/DataLayerServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace DataLayer.Startup;

/// <summary>
/// Registers the data layer's EF Core services with the application's DI container.
/// </summary>
public static class DataLayerServiceExtensions
{
public static IServiceCollection AddDataLayer(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString(DataClasses.SampleWebAppDbContext.ConnectionStringName);

if (string.IsNullOrWhiteSpace(connectionString))
{
throw new InvalidOperationException(
$"Connection string '{DataClasses.SampleWebAppDbContext.ConnectionStringName}' was not found.");
}

services.AddDbContext<DataClasses.SampleWebAppDbContext>(options =>
options.UseSqlServer(connectionString));

return services;
}
}
31 changes: 31 additions & 0 deletions src/SampleWebApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using SampleWebApp.Models;

namespace SampleWebApp.Controllers;

public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

public IActionResult Index()
{
return View();
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
8 changes: 8 additions & 0 deletions src/SampleWebApp/Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SampleWebApp.Models;

public class ErrorViewModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
35 changes: 35 additions & 0 deletions src/SampleWebApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using BizLayer.Startup;
using DataLayer.Startup;
using ServiceLayer.Startup;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

// Register layered application services (DI container).
builder.Services.AddDataLayer(builder.Configuration);
builder.Services.AddServiceLayer();
builder.Services.AddBizLayer();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();
28 changes: 28 additions & 0 deletions src/SampleWebApp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:33156",
"sslPort": 44323
}
},
"profiles": {
"SampleWebApp": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7131;http://localhost:5191",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
22 changes: 22 additions & 0 deletions src/SampleWebApp/SampleWebApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<ItemGroup>
<ProjectReference Include="..\DataLayer\DataLayer.csproj" />
<ProjectReference Include="..\BizLayer\BizLayer.csproj" />
<ProjectReference Include="..\ServiceLayer\ServiceLayer.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.36">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
8 changes: 8 additions & 0 deletions src/SampleWebApp/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@{
ViewData["Title"] = "Home Page";
}

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
6 changes: 6 additions & 0 deletions src/SampleWebApp/Views/Home/Privacy.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
25 changes: 25 additions & 0 deletions src/SampleWebApp/Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
49 changes: 49 additions & 0 deletions src/SampleWebApp/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - SampleWebApp</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/SampleWebApp.styles.css" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">SampleWebApp</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2026 - SampleWebApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
Loading