Skip to content

Commit

Permalink
Update samples dependencies (#56)
Browse files Browse the repository at this point in the history
docs: Update samples dependencies
---------

Co-authored-by: Borja Domínguez Vázquez <bdominguez@virtualwareco.com>
  • Loading branch information
bdovaz and bdominguez authored Apr 24, 2024
1 parent 8e062d3 commit c7e8fca
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 79 deletions.
8 changes: 2 additions & 6 deletions samples/AuthGettingStarted/AuthGettingStarted.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Api</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Serilog.AspNetCore" />
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 3 additions & 9 deletions samples/AuthZGettingStarted/AuthZGettingStarted.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.SpectreConsole" Version="0.3.3" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Serilog.Extensions.Hosting" />
<PackageReference Include="Serilog.Sinks.SpectreConsole" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Api.Application.Authorization;
namespace Api.Application.Authorization;

using Abstractions;
using MediatR;
Expand All @@ -17,8 +17,8 @@ public AuthorizationBehavior(IIdentityService identityService, ILogger<TRequest>

public async Task<TResponse> Handle(
TRequest request,
CancellationToken cancellationToken,
RequestHandlerDelegate<TResponse> next)
RequestHandlerDelegate<TResponse> next,
CancellationToken cancellationToken)
{
// TODO: consider reflection performance impact
var authorizeAttributes = request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ namespace Api.Application.Commands;

using System.Threading;
using System.Threading.Tasks;
using Data;
using Authorization;
using Authorization.Abstractions;
using Data;
using Keycloak.AuthServices.Sdk.Admin;
using Keycloak.AuthServices.Sdk.Admin.Models;
using MediatR;
Expand All @@ -28,24 +28,23 @@ public CreateWorkspaceCommandHandler(
this.identityService = identityService ?? throw new ArgumentNullException(nameof(identityService));
}

public async Task<Unit> Handle(
public async Task Handle(
CreateWorkspaceCommand request,
CancellationToken cancellationToken)
{
var (name, projects) = request;

var workspace = new Workspace {Name = name, Projects = projects ?? new List<Project>()};
var workspace = new Workspace { Name = name, Projects = projects ?? new List<Project>() };
this.db.Workspaces.Add(workspace);
await this.db.SaveChangesAsync(cancellationToken);

var userName = this.identityService?.UserName
?? throw new InvalidOperationException();
await this.resourceClient.CreateResource("authz",
new Resource($"workspaces/{workspace.Id}", new[] {"workspaces:read", "workspaces:delete"})
new Resource($"workspaces/{workspace.Id}", new[] { "workspaces:read", "workspaces:delete" })
{
Attributes = {[userName] = "Owner"},
Attributes = { [userName] = "Owner" },
Type = "urn:workspace-authz:resource:workspaces",
});
return Unit.Value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ namespace Api.Application.Commands;

using System.Threading;
using System.Threading.Tasks;
using Data;
using Authorization;
using Authorization.Abstractions;
using Data;
using Keycloak.AuthServices.Authorization;
using MediatR;

Expand All @@ -21,7 +21,7 @@ public DeleteWorkspaceCommandHandler(IApplicationDbContext db, IIdentityService
this.identityService = identityService;
}

public async Task<Unit> Handle(
public async Task Handle(
DeleteWorkspaceCommand request,
CancellationToken cancellationToken)
{
Expand All @@ -35,7 +35,5 @@ public async Task<Unit> Handle(
var workspace = new Workspace() { Id = request.Id };
this.db.Workspaces.Remove(workspace);
await this.db.SaveChangesAsync(cancellationToken);

return Unit.Value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ namespace Api.Application.Commands;

using System.Threading;
using System.Threading.Tasks;
using Data;
using Authorization;
using Data;
using MediatR;

[AuthorizeProtectedResource(
Expand All @@ -21,14 +21,12 @@ public class DeleteWorkspaceCommandAOPHandler : IRequestHandler<DeleteWorkspaceC
public DeleteWorkspaceCommandAOPHandler(IApplicationDbContext db) =>
this.db = db;

public async Task<Unit> Handle(
public async Task Handle(
DeleteWorkspaceCommandAOP request,
CancellationToken cancellationToken)
{
var workspace = new Workspace() {Id = request.Id};
var workspace = new Workspace() { Id = request.Id };
this.db.Workspaces.Remove(workspace);
await this.db.SaveChangesAsync(cancellationToken);

return Unit.Value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ namespace Api.Application.Queries;

using System.Threading;
using System.Threading.Tasks;
using Data;
using Authorization;
using Authorization.Abstractions;
using Data;
using Keycloak.AuthServices.Authorization;
using MediatR;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -38,7 +38,7 @@ public async Task<Workspace> Handle(
var workspace = await this.db
.Workspaces
.Include(w => w.Projects)
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
.FirstAsync(x => x.Id == request.Id, cancellationToken);

return workspace;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Api</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="10.0.1" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5">
<PackageReference Include="MediatR" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.5.1" />
<PackageReference Include="Serilog.AspNetCore" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public async Task<IActionResult> GetResource(string id)
[HttpPost("resources")]
public async Task<IActionResult> CreateResource()
{
var resource = new Resource($"workspaces/{Guid.NewGuid()}", new[] {"workspaces:read", "workspaces:delete"})
var resource = new Resource($"workspaces/{Guid.NewGuid()}", new[] { "workspaces:read", "workspaces:delete" })
{
Attributes = {["test"] = "Owner, Operations"}, Type = "urn:workspace-authz:resource:workspaces",
Attributes = { ["test"] = "Owner, Operations" },
Type = "urn:workspace-authz:resource:workspaces",
};
return this.Ok(await this.protectedResourceClient.CreateResource(DefaultRealm, resource));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Api.Filters
namespace Api.Filters
{
using Application.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -30,7 +30,7 @@ public override void OnException(ExceptionContext context)

private void HandleException(ExceptionContext context)
{
Type type = context.Exception.GetType();
var type = context.Exception.GetType();
if (this.exceptionHandlers.ContainsKey(type))
{
this.exceptionHandlers[type].Invoke(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(
configuration.GetConnectionString("DefaultConnection"),
configuration.GetConnectionString("DefaultConnection")!,
b => b.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)));

services.AddScoped<IApplicationDbContext, ApplicationDbContext>
Expand All @@ -30,7 +30,7 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi
}
public static IServiceCollection AddApplication(this IServiceCollection services)
{
services.AddMediatR(Assembly.GetExecutingAssembly());
services.AddMediatR(configuration => configuration.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(AuthorizationBehavior<,>));
// services.AddTransient(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehavior<,>));
// services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
Expand Down
15 changes: 4 additions & 11 deletions samples/Blazor/Client/Blazor.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

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

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.5" PrivateAssets="all" />
<!--<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.11" />-->
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.11" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" />
<PackageReference Include="Microsoft.Extensions.Http" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 3 additions & 10 deletions samples/Blazor/Server/Blazor.Server.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.5" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" />
<PackageReference Include="Serilog.AspNetCore" />
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions samples/Blazor/Shared/Blazor.Shared.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

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

Expand Down
11 changes: 11 additions & 0 deletions samples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions samples/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project>
<ItemGroup>
<PackageVersion Include="MediatR" Version="12.2.0"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.29"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.29"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.29"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.29"/>
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.29"/>
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0"/>
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11"/>
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.1"/>
<PackageVersion Include="Serilog.Extensions.Hosting" Version="8.0.0"/>
<PackageVersion Include="Serilog.Sinks.SpectreConsole" Version="0.3.3"/>
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit c7e8fca

Please sign in to comment.