Skip to content

Commit 776d1b5

Browse files
committed
Remove complexity from layout view
1 parent 7ed4488 commit 776d1b5

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

src/SchoolAccount.Web.Mvc/DependencyInjection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using GovUk.Frontend.AspNetCore;
22
using SchoolAccount.Web.Mvc.Authentication.Extensions;
3+
using SchoolAccount.Web.Mvc.Features.Header;
34
using SchoolAccount.Web.Mvc.Infrastructure;
45

56
namespace SchoolAccount.Web.Mvc;
@@ -16,6 +17,7 @@ IConfigurationManager configuration
1617
services.AddDsiAuthentication(configuration);
1718
services.AddControllersWithFeatureViews();
1819
services.AddGovUkFrontend();
20+
services.AddScoped<IHeaderContentProvider, HeaderContentProvider>();
1921

2022
if (env.IsDevelopment())
2123
{
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using SchoolAccount.SharedKernel;
2+
3+
namespace SchoolAccount.Web.Mvc.Features.Header;
4+
5+
public interface IHeaderContentProvider
6+
{
7+
bool IsAuthenticated { get; }
8+
string? OrganisationName { get; }
9+
}
10+
11+
public class HeaderContentProvider : IHeaderContentProvider
12+
{
13+
public bool IsAuthenticated { get; }
14+
public string? OrganisationName { get; }
15+
16+
public HeaderContentProvider(IUserContext userContext)
17+
{
18+
IsAuthenticated = userContext.IsAuthenticated;
19+
OrganisationName = userContext.Organisation?.Name;
20+
}
21+
}

src/SchoolAccount.Web.Mvc/Features/Shared/_Layout.cshtml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
@using SchoolAccount.SharedKernel
2-
@inject IUserContext CurrentUser
1+
@using SchoolAccount.Web.Mvc.Features.Header
2+
@inject IHeaderContentProvider HeaderContentProvider
33

44
@* ReSharper disable Razor.LayoutNotResolved *@
55
@* ReSharper disable Razor.SectionNotResolved *@
66

77
@{
88
Layout = "_GovUkPageTemplate";
9-
10-
var isAuthenticated = CurrentUser?.IsAuthenticated == true;
11-
var organisationName = CurrentUser?.Organisation?.Name;
129
}
1310

1411
@section Head {
@@ -26,9 +23,9 @@
2623
</a>
2724
</div>
2825
<div class="header-navigation">
29-
@if (isAuthenticated)
26+
@if (HeaderContentProvider.IsAuthenticated)
3027
{
31-
<span class="header-navigation__school">@organisationName</span>
28+
<span class="header-navigation__school">@HeaderContentProvider.OrganisationName</span>
3229

3330
@using (Html.BeginForm("Logout", "Account", FormMethod.Post))
3431
{

0 commit comments

Comments
 (0)