Skip to content

Commit

Permalink
BlazorShared and Services (dotnet-architecture#430)
Browse files Browse the repository at this point in the history
* Service to Services

* Change Shared project to BlazorShared

* change refrerances to BlazorShared
  • Loading branch information
ShadyNagy authored Jul 25, 2020
1 parent f4bfc81 commit e1f9ddd
Show file tree
Hide file tree
Showing 46 changed files with 87 additions and 76 deletions.
12 changes: 6 additions & 6 deletions eShopOnWeb.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PublicApi", "src\PublicApi\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorAdmin", "src\BlazorAdmin\BlazorAdmin.csproj", "{71368733-80A4-4869-B215-3A7001878577}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "src\Shared\Shared.csproj", "{7BDB419E-FAC1-4D43-8AA9-FB61EBE31BB8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorShared", "src\BlazorShared\BlazorShared.csproj", "{715CF7AF-A1EE-40A6-94A0-8DA3F3B2CAE9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -78,10 +78,10 @@ Global
{71368733-80A4-4869-B215-3A7001878577}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71368733-80A4-4869-B215-3A7001878577}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71368733-80A4-4869-B215-3A7001878577}.Release|Any CPU.Build.0 = Release|Any CPU
{7BDB419E-FAC1-4D43-8AA9-FB61EBE31BB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BDB419E-FAC1-4D43-8AA9-FB61EBE31BB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BDB419E-FAC1-4D43-8AA9-FB61EBE31BB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BDB419E-FAC1-4D43-8AA9-FB61EBE31BB8}.Release|Any CPU.Build.0 = Release|Any CPU
{715CF7AF-A1EE-40A6-94A0-8DA3F3B2CAE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{715CF7AF-A1EE-40A6-94A0-8DA3F3B2CAE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{715CF7AF-A1EE-40A6-94A0-8DA3F3B2CAE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{715CF7AF-A1EE-40A6-94A0-8DA3F3B2CAE9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -95,7 +95,7 @@ Global
{7EFB5482-F942-4C3D-94B0-9B70596E6D0A} = {15EA4737-125B-4E6E-A806-E13B7EBCDCCF}
{B5E4F33C-4667-4A55-AF6A-740F84C4CF3A} = {419A6ACE-0419-4315-A6FB-B0E63D39432E}
{71368733-80A4-4869-B215-3A7001878577} = {419A6ACE-0419-4315-A6FB-B0E63D39432E}
{7BDB419E-FAC1-4D43-8AA9-FB61EBE31BB8} = {419A6ACE-0419-4315-A6FB-B0E63D39432E}
{715CF7AF-A1EE-40A6-94A0-8DA3F3B2CAE9} = {419A6ACE-0419-4315-A6FB-B0E63D39432E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {49813262-5DA3-4D61-ABD3-493C74CE8C2B}
Expand Down
4 changes: 4 additions & 0 deletions src/ApplicationCore/ApplicationCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
<PackageReference Include="System.Text.Json" Version="4.7.2" />
</ItemGroup>

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

</Project>
4 changes: 0 additions & 4 deletions src/ApplicationCore/Constants/AuthorizationConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
{
public class AuthorizationConstants
{
public static class Roles
{
public const string ADMINISTRATORS = "Administrators";
}

// TODO: Don't use this in production
public const string DEFAULT_PASSWORD = "Pass@word1";
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorAdmin/BlazorAdmin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\BlazorShared\BlazorShared.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 0 additions & 5 deletions src/BlazorAdmin/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@
public class Constants
{
public const string API_URL = "https://localhost:5099/api/";

public static class Roles
{
public const string ADMINISTRATORS = "Administrators";
}
}
}
2 changes: 1 addition & 1 deletion src/BlazorAdmin/CustomAuthStateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Shared.Authorization;
using BlazorShared.Authorization;

namespace BlazorAdmin
{
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorAdmin/Pages/CatalogItemPage/Create.razor
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

private async Task CreateClick()
{
await new BlazorAdmin.Services.CatalogItemService.Create(Auth).HandleAsync(_item);
await new BlazorAdmin.Services.CatalogItemServices.Create(Auth).HandleAsync(_item);
await OnCloseClick.InvokeAsync(null);
Close();
}
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorAdmin/Pages/CatalogItemPage/Delete.razor
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@
</dt>

<dd>
@Services.CatalogBrandService.List.GetBrandName(Brands, _item.CatalogBrandId)
@Services.CatalogBrandServices.List.GetBrandName(Brands, _item.CatalogBrandId)
</dd>

<dt>
Type
</dt>

<dd>
@Services.CatalogTypeService.List.GetTypeName(Types, _item.CatalogTypeId)
@Services.CatalogTypeServices.List.GetTypeName(Types, _item.CatalogTypeId)
</dd>
<dt>
Price
Expand Down Expand Up @@ -105,7 +105,7 @@
{
// TODO: Add some kind of "are you sure" check before this
await new BlazorAdmin.Services.CatalogItemService.Delete(Auth).HandleAsync(id);
await new BlazorAdmin.Services.CatalogItemServices.Delete(Auth).HandleAsync(id);

await OnCloseClick.InvokeAsync(null);
Close();
Expand Down
4 changes: 2 additions & 2 deletions src/BlazorAdmin/Pages/CatalogItemPage/Details.razor
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@
</dt>

<dd>
@Services.CatalogBrandService.List.GetBrandName(Brands, _item.CatalogBrandId)
@Services.CatalogBrandServices.List.GetBrandName(Brands, _item.CatalogBrandId)
</dd>

<dt>
Type
</dt>

<dd>
@Services.CatalogTypeService.List.GetTypeName(Types, _item.CatalogTypeId)
@Services.CatalogTypeServices.List.GetTypeName(Types, _item.CatalogTypeId)
</dd>
<dt>
Price
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorAdmin/Pages/CatalogItemPage/Edit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

private async Task SaveClick()
{
await new BlazorAdmin.Services.CatalogItemService.Edit(Auth).HandleAsync(_item);
await new BlazorAdmin.Services.CatalogItemServices.Edit(Auth).HandleAsync(_item);
Close();
}

Expand Down
8 changes: 4 additions & 4 deletions src/BlazorAdmin/Pages/CatalogItemPage/List.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@page "/admin"
@attribute [Authorize(Roles = Constants.Roles.ADMINISTRATORS)]
@attribute [Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS)]
@inject AuthService Auth
@using global::Shared.Authorization
@using global::BlazorShared.Authorization
@inherits BlazorAdmin.Helpers.BlazorComponent
@namespace BlazorAdmin.Pages.CatalogItemPage

Expand Down Expand Up @@ -40,8 +40,8 @@ else
<td>
<img class="img-thumbnail" src="@($"https://localhost:44315/{item.PictureUri}")">
</td>
<td>@Services.CatalogTypeService.List.GetTypeName(catalogTypes, item.CatalogTypeId)</td>
<td>@Services.CatalogBrandService.List.GetBrandName(catalogBrands, item.CatalogBrandId)</td>
<td>@Services.CatalogTypeServices.List.GetTypeName(catalogTypes, item.CatalogTypeId)</td>
<td>@Services.CatalogBrandServices.List.GetBrandName(catalogBrands, item.CatalogBrandId)</td>
<td>@item.Id</td>
<td>@item.Name</td>
<td>@item.Description</td>
Expand Down
14 changes: 7 additions & 7 deletions src/BlazorAdmin/Pages/CatalogItemPage/List.razor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using BlazorAdmin.Helpers;
using BlazorAdmin.Services.CatalogBrandService;
using BlazorAdmin.Services.CatalogItemService;
using BlazorAdmin.Services.CatalogTypeService;
using BlazorAdmin.Services.CatalogBrandServices;
using BlazorAdmin.Services.CatalogItemServices;
using BlazorAdmin.Services.CatalogTypeServices;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand All @@ -22,9 +22,9 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
catalogItems = await new BlazorAdmin.Services.CatalogItemService.ListPaged(Auth).HandleAsync(50);
catalogTypes = await new BlazorAdmin.Services.CatalogTypeService.List(Auth).HandleAsync();
catalogBrands = await new BlazorAdmin.Services.CatalogBrandService.List(Auth).HandleAsync();
catalogItems = await new BlazorAdmin.Services.CatalogItemServices.ListPaged(Auth).HandleAsync(50);
catalogTypes = await new BlazorAdmin.Services.CatalogTypeServices.List(Auth).HandleAsync();
catalogBrands = await new BlazorAdmin.Services.CatalogBrandServices.List(Auth).HandleAsync();

CallRequestRefresh();
}
Expand Down Expand Up @@ -54,7 +54,7 @@ private async Task DeleteClick(int id)

private async Task ReloadCatalogItems()
{
catalogItems = await new BlazorAdmin.Services.CatalogItemService.ListPaged(Auth).HandleAsync(50);
catalogItems = await new BlazorAdmin.Services.CatalogItemServices.ListPaged(Auth).HandleAsync(50);
StateHasChanged();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorAdmin/Services/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Blazored.LocalStorage;
using Microsoft.JSInterop;
using Newtonsoft.Json;
using Shared.Authorization;
using BlazorShared.Authorization;

namespace BlazorAdmin.Services
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BlazorAdmin.Services.CatalogBrandService
namespace BlazorAdmin.Services.CatalogBrandServices
{
public class CatalogBrand
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace BlazorAdmin.Services.CatalogBrandService
namespace BlazorAdmin.Services.CatalogBrandServices
{
public class CatalogBrandResult
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Newtonsoft.Json;

namespace BlazorAdmin.Services.CatalogBrandService
namespace BlazorAdmin.Services.CatalogBrandServices
{
public class List
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;

namespace BlazorAdmin.Services.CatalogItemService
namespace BlazorAdmin.Services.CatalogItemServices
{
public class CatalogItem
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;

namespace BlazorAdmin.Services.CatalogItemService
namespace BlazorAdmin.Services.CatalogItemServices
{
public class CreateCatalogItemRequest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Threading.Tasks;

namespace BlazorAdmin.Services.CatalogItemService
namespace BlazorAdmin.Services.CatalogItemServices
{
public class CreateCatalogItemResult
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace BlazorAdmin.Services.CatalogItemService
namespace BlazorAdmin.Services.CatalogItemServices
{
public class Create
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BlazorAdmin.Services.CatalogItemService
namespace BlazorAdmin.Services.CatalogItemServices
{
public class DeleteCatalogItemResult
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace BlazorAdmin.Services.CatalogItemService
namespace BlazorAdmin.Services.CatalogItemServices
{
public class Delete
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BlazorAdmin.Services.CatalogItemService
namespace BlazorAdmin.Services.CatalogItemServices
{
public class EditCatalogItemResult
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace BlazorAdmin.Services.CatalogItemService
namespace BlazorAdmin.Services.CatalogItemServices
{
public class Edit
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BlazorAdmin.Services.CatalogItemService
namespace BlazorAdmin.Services.CatalogItemServices
{
public class GetByIdCatalogItemResult
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace BlazorAdmin.Services.CatalogItemService
namespace BlazorAdmin.Services.CatalogItemServices
{
public class GetById
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace BlazorAdmin.Services.CatalogItemService
namespace BlazorAdmin.Services.CatalogItemServices
{
public class PagedCatalogItemResult
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace BlazorAdmin.Services.CatalogItemService
namespace BlazorAdmin.Services.CatalogItemServices
{
public class ListPaged
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BlazorAdmin.Services.CatalogTypeService
namespace BlazorAdmin.Services.CatalogTypeServices
{
public class CatalogType
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace BlazorAdmin.Services.CatalogTypeService
namespace BlazorAdmin.Services.CatalogTypeServices
{
public class CatalogTypeResult
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Newtonsoft.Json;

namespace BlazorAdmin.Services.CatalogTypeService
namespace BlazorAdmin.Services.CatalogTypeServices
{
public class List
{
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorAdmin/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@inherits BlazorAdmin.Helpers.BlazorLayoutComponent

<AuthorizeView Roles=@Constants.Roles.ADMINISTRATORS>
<AuthorizeView Roles=@BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS>
<div class="sidebar">
<NavMenu />
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorAdmin/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
@using BlazorAdmin
@using BlazorAdmin.Shared
@using BlazorAdmin.Services
@using BlazorAdmin.Services.CatalogBrandService
@using BlazorAdmin.Services.CatalogItemService
@using BlazorAdmin.Services.CatalogTypeService
@using BlazorAdmin.Services.CatalogBrandServices
@using BlazorAdmin.Services.CatalogItemServices
@using BlazorAdmin.Services.CatalogTypeServices
@using Microsoft.Extensions.Logging
@using BlazorAdmin.JavaScript
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace Shared.Authorization
namespace BlazorShared.Authorization
{
public class ClaimValue
{
Expand Down
14 changes: 14 additions & 0 deletions src/BlazorShared/Authorization/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace BlazorShared.Authorization
{
public class Constants
{
public static class Roles
{
public const string ADMINISTRATORS = "Administrators";
}
}
}
Loading

0 comments on commit e1f9ddd

Please sign in to comment.