ajout classe d'extension
This commit is contained in:
parent
f9eeb453ac
commit
5ca2b509fe
@ -18,6 +18,12 @@ public class HomeController : Controller
|
|||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("/404")]
|
||||||
|
public IActionResult Status404()
|
||||||
|
{
|
||||||
|
return View("404");
|
||||||
|
}
|
||||||
|
|
||||||
public IActionResult Privacy()
|
public IActionResult Privacy()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
using HackerNet.Application;
|
using HackerNet.Application;
|
||||||
using HackerNet.Web.Filters;
|
using HackerNet.Infrastructure.AspNet.Filters;
|
||||||
using HackerNet.Web.Models;
|
using HackerNet.Web.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ public class LinksController : HackerController
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[TypeFilter(typeof(CustomExceptionFilter))]
|
[CustomExceptionFilter]
|
||||||
public IActionResult Detail(Guid id)
|
public IActionResult Detail(Guid id)
|
||||||
{
|
{
|
||||||
var link = _linkService.GetLinkDetail(id);
|
var link = _linkService.GetLinkDetail(id);
|
||||||
|
|||||||
@ -1,24 +1,14 @@
|
|||||||
using HackerNet.Application;
|
using HackerNet.Infrastructure.AspNet;
|
||||||
using HackerNet.Domain;
|
|
||||||
using HackerNet.Infrastructure.Repositories.Memory;
|
|
||||||
using HackerNet.Web.Filters;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
var link = new Link("https://localhost:7050/", "Youhouuu");
|
//ServiceCollectionExtensions.AddHackerNetServices(builder.Services);
|
||||||
var comment = new Comment(link.Id, "Wow!");
|
builder.Services
|
||||||
var linksRepository = new MemoryLinkRepository(link);
|
.AddHackerNetServices()
|
||||||
var commentsRepository = new MemoryCommentRepository(comment);
|
.AddControllersWithViews(o =>
|
||||||
|
|
||||||
builder.Services.AddSingleton<ILinkRepository>(linksRepository);
|
|
||||||
builder.Services.AddSingleton<ICommentRepository>(commentsRepository);
|
|
||||||
builder.Services.AddSingleton<IReadStore>(new MemoryReadStore(linksRepository, commentsRepository));
|
|
||||||
|
|
||||||
builder.Services.AddSingleton<LinkService>();
|
|
||||||
builder.Services.AddControllersWithViews(o =>
|
|
||||||
{
|
{
|
||||||
o.Filters.Add<CustomExceptionFilter>();
|
//o.Filters.Add<CustomExceptionFilter>();
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
@ -60,7 +50,7 @@ app.Use(async (ctx, next) =>
|
|||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
||||||
// app.UseStatusCodePages()
|
app.UseStatusCodePagesWithRedirects("/{0}");
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
|
|||||||
5
Apps/HackerNet.Web/Views/Home/404.cshtml
Normal file
5
Apps/HackerNet.Web/Views/Home/404.cshtml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Page non trouvée";
|
||||||
|
}
|
||||||
|
|
||||||
|
<p>Impossible de trouver la page que vous recherchez.</p>
|
||||||
@ -81,6 +81,7 @@ public class PublishCommentCommand
|
|||||||
{
|
{
|
||||||
public Guid LinkId { get; set; }
|
public Guid LinkId { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required(ErrorMessage = "Le contenu est obligatoire")]
|
||||||
|
[Display(Name = "Votre commentaire")]
|
||||||
public string Content { get; set; }
|
public string Content { get; set; }
|
||||||
}
|
}
|
||||||
@ -1,11 +1,11 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
|
||||||
namespace HackerNet.Web.Filters;
|
namespace HackerNet.Infrastructure.AspNet.Filters;
|
||||||
|
|
||||||
public class CustomExceptionFilter : IExceptionFilter
|
public class CustomExceptionFilter : ExceptionFilterAttribute
|
||||||
{
|
{
|
||||||
public void OnException(ExceptionContext context)
|
public override void OnException(ExceptionContext context)
|
||||||
{
|
{
|
||||||
if (context.Exception is InvalidOperationException)
|
if (context.Exception is InvalidOperationException)
|
||||||
{
|
{
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
using HackerNet.Application;
|
||||||
|
using HackerNet.Domain;
|
||||||
|
using HackerNet.Infrastructure.Repositories.Memory;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
namespace HackerNet.Infrastructure.AspNet;
|
||||||
|
|
||||||
|
public static class ServiceCollectionExtensions
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddHackerNetServices(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
var link = new Link("https://localhost:7050/", "Youhouuu");
|
||||||
|
var comment = new Comment(link.Id, "Wow!");
|
||||||
|
var linksRepository = new MemoryLinkRepository(link);
|
||||||
|
var commentsRepository = new MemoryCommentRepository(comment);
|
||||||
|
|
||||||
|
services.AddSingleton<ILinkRepository>(linksRepository);
|
||||||
|
services.AddSingleton<ICommentRepository>(commentsRepository);
|
||||||
|
services.AddSingleton<IReadStore>(new MemoryReadStore(linksRepository, commentsRepository));
|
||||||
|
|
||||||
|
services.AddSingleton<LinkService>();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
<ProjectReference Include="..\HackerNet.Application\HackerNet.Application.csproj" />
|
<ProjectReference Include="..\HackerNet.Application\HackerNet.Application.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user