Skip to content

Commit bdbc81f

Browse files
committed
Add Clean Architecture WebApp sample and implement minor changes
1 parent ef8a8fe commit bdbc81f

File tree

74 files changed

+1868
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1868
-125
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System.Reflection;
2+
3+
namespace Project.Application;
4+
5+
public static class AssemblyReference
6+
{
7+
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly;
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using KSFramework.KSMessaging.Abstraction;
2+
3+
namespace Project.Application.Blog.CreatePost;
4+
5+
public record CreatePostCommand : ICommand<CreatePostResponse>
6+
{
7+
public required string Title { get; set; }
8+
public required string Content { get; set; }
9+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using KSFramework.GenericRepository;
2+
using KSFramework.KSMessaging;
3+
using KSFramework.KSMessaging.Abstraction;
4+
using Project.Domain.Aggregates.Blog;
5+
6+
namespace Project.Application.Blog.CreatePost;
7+
8+
public sealed class CreatePostCommandHandler(IUnitOfWork unitOfWork) : CqrsBase(unitOfWork),
9+
ICommandHandler<CreatePostCommand, CreatePostResponse>
10+
{
11+
private readonly IUnitOfWork _unitOfWork = unitOfWork;
12+
13+
public async Task<CreatePostResponse> Handle(CreatePostCommand request, CancellationToken cancellationToken)
14+
{
15+
Post post = Post.Create(request.Title, request.Content);
16+
await _unitOfWork.GetRepository<Post>()
17+
.AddAsync(post);
18+
await _unitOfWork.SaveChangesAsync();
19+
20+
return new CreatePostResponse(post.Id, post.Slug);
21+
}
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using FluentValidation;
2+
3+
namespace Project.Application.Blog.CreatePost;
4+
5+
public sealed class CreatePostCommandValidator : AbstractValidator<CreatePostCommand>
6+
{
7+
public CreatePostCommandValidator()
8+
{
9+
RuleFor(x => x.Title)
10+
.NotNull()
11+
.NotEmpty()
12+
.Length(10, 500);
13+
14+
RuleFor(x => x.Content)
15+
.NotNull()
16+
.NotEmpty();
17+
}
18+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Project.Application.Blog.CreatePost;
2+
3+
public record CreatePostRequest(string Title, string Content);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Project.Application.Blog.CreatePost;
2+
3+
public record CreatePostResponse(Guid Id, string Slug);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using KSFramework.KSMessaging.Extensions;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.Extensions.DependencyInjection;
4+
5+
namespace Project.Application;
6+
7+
public static class DependencyInjection
8+
{
9+
public static IServiceCollection RegisterApplication(this IServiceCollection services)
10+
{
11+
services.AddKSMediator(Project.Application.AssemblyReference.Assembly);
12+
return services;
13+
}
14+
15+
public static WebApplication UseApplication(this WebApplication app)
16+
{
17+
return app;
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\Project.Domain\Project.Domain.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Project.ClientApp.Models;
4+
5+
namespace Project.ClientApp.Controllers;
6+
7+
public class HomeController : Controller
8+
{
9+
public IActionResult Index()
10+
{
11+
return View();
12+
}
13+
14+
public IActionResult Privacy()
15+
{
16+
return View();
17+
}
18+
19+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
20+
public IActionResult Error()
21+
{
22+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
23+
}
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Project.ClientApp.Models;
2+
3+
public class ErrorViewModel
4+
{
5+
public string? RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}

0 commit comments

Comments
 (0)