Skip to content

Commit

Permalink
update to .net 9
Browse files Browse the repository at this point in the history
  • Loading branch information
iammukeshm committed Nov 22, 2024
1 parent 80b3820 commit a840da2
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 60 deletions.
4 changes: 3 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.11.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="9.0.0" />
<PackageVersion Include="Microsoft.NET.Build.Containers" Version="8.0.100" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageVersion Include="MimeKit" Version="4.8.0" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.1" />
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.12" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Process" Version="0.5.0-beta.6" />
Expand Down Expand Up @@ -78,6 +79,7 @@
</ItemGroup>
<ItemGroup Label="Aspire">
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageVersion Include="Aspire.AppHost.Sdk" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.10.0" />
Expand Down
6 changes: 3 additions & 3 deletions src/Shared/Authorization/AppConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace FSH.Starter.Shared.Authorization;
public static class AppConstants
{
public static readonly Collection<string> SupportedImageFormats = new()
{
public static readonly Collection<string> SupportedImageFormats =
[
".jpeg",
".jpg",
".png"
};
];
public static readonly string StandardImageFormat = "image/jpeg";
public static readonly int MaxImageWidth = 1500;
public static readonly int MaxImageHeight = 1500;
Expand Down
14 changes: 7 additions & 7 deletions src/Shared/Authorization/FshPermissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace FSH.Starter.Shared.Authorization;

public static class FshPermissions
{
private static readonly FshPermission[] allPermissions =
{
private static readonly FshPermission[] AllPermissions =
[
//tenants
new("View Tenants", FshActions.View, FshResources.Tenants, IsRoot: true),
new("Create Tenants", FshActions.Create, FshResources.Tenants, IsRoot: true),
Expand Down Expand Up @@ -49,12 +49,12 @@ public static class FshPermissions

//audit
new("View Audit Trails", FshActions.View, FshResources.AuditTrails),
};
];

public static IReadOnlyList<FshPermission> All { get; } = new ReadOnlyCollection<FshPermission>(allPermissions);
public static IReadOnlyList<FshPermission> Root { get; } = new ReadOnlyCollection<FshPermission>(allPermissions.Where(p => p.IsRoot).ToArray());
public static IReadOnlyList<FshPermission> Admin { get; } = new ReadOnlyCollection<FshPermission>(allPermissions.Where(p => !p.IsRoot).ToArray());
public static IReadOnlyList<FshPermission> Basic { get; } = new ReadOnlyCollection<FshPermission>(allPermissions.Where(p => p.IsBasic).ToArray());
public static IReadOnlyList<FshPermission> All { get; } = new ReadOnlyCollection<FshPermission>(AllPermissions);
public static IReadOnlyList<FshPermission> Root { get; } = new ReadOnlyCollection<FshPermission>(AllPermissions.Where(p => p.IsRoot).ToArray());
public static IReadOnlyList<FshPermission> Admin { get; } = new ReadOnlyCollection<FshPermission>(AllPermissions.Where(p => !p.IsRoot).ToArray());
public static IReadOnlyList<FshPermission> Basic { get; } = new ReadOnlyCollection<FshPermission>(AllPermissions.Where(p => p.IsBasic).ToArray());
}

public record FshPermission(string Description, string Action, string Resource, bool IsBasic = false, bool IsRoot = false)
Expand Down
18 changes: 9 additions & 9 deletions src/api/framework/Core/Audit/TrailDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ public class TrailDto()
public Guid Id { get; set; }
public DateTimeOffset DateTime { get; set; }
public Guid UserId { get; set; }
public Dictionary<string, object?> KeyValues { get; } = new();
public Dictionary<string, object?> OldValues { get; } = new();
public Dictionary<string, object?> NewValues { get; } = new();
public Collection<string> ModifiedProperties { get; } = new();
public Dictionary<string, object?> KeyValues { get; } = [];
public Dictionary<string, object?> OldValues { get; } = [];
public Dictionary<string, object?> NewValues { get; } = [];
public Collection<string> ModifiedProperties { get; } = [];
public TrailType Type { get; set; }
public string? TableName { get; set; }

private static readonly JsonSerializerOptions serializerOptions = new()
private static readonly JsonSerializerOptions SerializerOptions = new()
{
WriteIndented = false,
};
Expand All @@ -28,10 +28,10 @@ public AuditTrail ToAuditTrail()
Operation = Type.ToString(),
Entity = TableName,
DateTime = DateTime,
PrimaryKey = JsonSerializer.Serialize(KeyValues, serializerOptions),
PreviousValues = OldValues.Count == 0 ? null : JsonSerializer.Serialize(OldValues, serializerOptions),
NewValues = NewValues.Count == 0 ? null : JsonSerializer.Serialize(NewValues, serializerOptions),
ModifiedProperties = ModifiedProperties.Count == 0 ? null : JsonSerializer.Serialize(ModifiedProperties, serializerOptions)
PrimaryKey = JsonSerializer.Serialize(KeyValues, SerializerOptions),
PreviousValues = OldValues.Count == 0 ? null : JsonSerializer.Serialize(OldValues, SerializerOptions),
NewValues = NewValues.Count == 0 ? null : JsonSerializer.Serialize(NewValues, SerializerOptions),
ModifiedProperties = ModifiedProperties.Count == 0 ? null : JsonSerializer.Serialize(ModifiedProperties, SerializerOptions)
};
}
}
2 changes: 1 addition & 1 deletion src/api/framework/Core/Auth/Jwt/JwtOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
{
if (string.IsNullOrEmpty(Key))
{
yield return new ValidationResult("No Key defined in JwtSettings config", new[] { nameof(Key) });
yield return new ValidationResult("No Key defined in JwtSettings config", [nameof(Key)]);
}
}
}
7 changes: 3 additions & 4 deletions src/api/framework/Core/Exceptions/ForbiddenException.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System.Collections.ObjectModel;
using System.Net;
using System.Net;

namespace FSH.Framework.Core.Exceptions;
public class ForbiddenException : FshException
{
public ForbiddenException()
: base("unauthorized", new Collection<string>(), HttpStatusCode.Forbidden)
: base("unauthorized", [], HttpStatusCode.Forbidden)
{
}
public ForbiddenException(string message)
: base(message, new Collection<string>(), HttpStatusCode.Forbidden)
: base(message, [], HttpStatusCode.Forbidden)
{
}
}
12 changes: 6 additions & 6 deletions src/api/framework/Infrastructure/SecurityHeaders/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ internal static IServiceCollection ConfigureSecurityHeaders(this IServiceCollect

return services;
}

internal static IApplicationBuilder UseSecurityHeaders(this IApplicationBuilder app)
{
var options = app.ApplicationServices.GetRequiredService<IOptions<SecurityHeaderOptions>>().Value;

if (options.Enable)
{
app.Use(async (context, next) =>
Expand Down Expand Up @@ -48,22 +48,22 @@ internal static IApplicationBuilder UseSecurityHeaders(this IApplicationBuilder
{
context.Response.Headers.XXSSProtection = options.Headers.XXSSProtection;
}

if (!string.IsNullOrWhiteSpace(options.Headers.ContentSecurityPolicy))
{
context.Response.Headers.ContentSecurityPolicy = options.Headers.ContentSecurityPolicy;
}

if (!string.IsNullOrWhiteSpace(options.Headers.StrictTransportSecurity))
{
context.Response.Headers.StrictTransportSecurity = options.Headers.StrictTransportSecurity;
}
}

await next.Invoke();
});
}

return app;
}
}
6 changes: 3 additions & 3 deletions src/api/framework/Infrastructure/Tenant/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public static IServiceCollection ConfigureMultitenancy(this IServiceCollection s
{
// to save database calls to resolve tenant
// this was happening for every request earlier, leading to ineffeciency
config.Events.OnTenantResolved = async (context) =>
config.Events.OnTenantResolveCompleted = async (context) =>
{
if (context.StoreType != typeof(DistributedCacheStore<FshTenantInfo>))
if (context.MultiTenantContext.StoreInfo!.StoreType != typeof(DistributedCacheStore<FshTenantInfo>))
{
var sp = ((HttpContext)context.Context!).RequestServices;
var distributedCacheStore = sp
.GetService<IEnumerable<IMultiTenantStore<FshTenantInfo>>>()!
.FirstOrDefault(s => s.GetType() == typeof(DistributedCacheStore<FshTenantInfo>));

await distributedCacheStore!.TryAddAsync((FshTenantInfo)context.TenantInfo!);
await distributedCacheStore!.TryAddAsync(context.MultiTenantContext.TenantInfo!);
}
await Task.FromResult(0);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "RoleNameIndex",
schema: "identity",
table: "Roles",
columns: new[] { "NormalizedName", "TenantId" },
columns: ["NormalizedName", "TenantId"],
unique: true);

migrationBuilder.CreateIndex(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
using MediatR;

namespace FSH.Starter.WebApi.Todo.Features.GetList.v1;
public record GetTodoListRequest(PaginationFilter filter) : IRequest<PagedList<TodoDto>>;
public record GetTodoListRequest(PaginationFilter Filter) : IRequest<PagedList<TodoDto>>;
8 changes: 4 additions & 4 deletions src/api/modules/Todo/Persistence/TodoDbInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public async Task MigrateAsync(CancellationToken cancellationToken)

public async Task SeedAsync(CancellationToken cancellationToken)
{
const string Title = "Hello World!";
const string Note = "This is your first task";
if (await context.Todos.FirstOrDefaultAsync(t => t.Title == Title, cancellationToken).ConfigureAwait(false) is null)
const string title = "Hello World!";
const string note = "This is your first task";
if (await context.Todos.FirstOrDefaultAsync(t => t.Title == title, cancellationToken).ConfigureAwait(false) is null)
{
var todo = TodoItem.Create(Title, Note);
var todo = TodoItem.Create(title, note);
await context.Todos.AddAsync(todo, cancellationToken);
await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
logger.LogInformation("[{Tenant}] seeding default todo data", context.TenantInfo!.Identifier);
Expand Down
1 change: 1 addition & 0 deletions src/api/server/Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PublishProfile>DefaultContainer</PublishProfile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
4 changes: 2 additions & 2 deletions src/apps/blazor/client/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<ItemGroup>
<PackageVersion Include="Mapster" Version="7.4.0" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.32.0.97167" />
<PackageVersion Include="MediatR" Version="12.4.0" />
<PackageVersion Include="MediatR" Version="12.4.1" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0" PrivateAssets="all" />
<PackageVersion Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.0" />
<PackageVersion Include="MudBlazor" Version="8.0.0-preview.4" />
<PackageVersion Include="MudBlazor" Version="7.15.0" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions src/apps/blazor/infrastructure/Auth/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using FSH.Starter.Blazor.Infrastructure.Auth.Jwt;
using FSH.Starter.Shared.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication.Internal;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using FSH.Starter.Shared.Authorization;

namespace FSH.Starter.Blazor.Infrastructure.Auth;
public static class Extensions
Expand All @@ -26,9 +26,9 @@ public static IServiceCollection AddAuthentication(this IServiceCollection servi

private static void RegisterPermissionClaims(AuthorizationOptions options)
{
foreach (var permission in FshPermissions.All)
foreach (var permission in FshPermissions.All.Select(p => p.Name))
{
options.AddPolicy(permission.Name, policy => policy.RequireClaim(FshClaims.Permission, permission.Name));
options.AddPolicy(permission, policy => policy.RequireClaim(FshClaims.Permission, permission));
}
}
}
2 changes: 1 addition & 1 deletion src/apps/blazor/infrastructure/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<PackageVersion Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.0" />
<PackageVersion Include="MudBlazor" Version="8.0.0-preview.4" />
<PackageVersion Include="MudBlazor" Version="7.15.0" />
</ItemGroup>
</Project>
26 changes: 13 additions & 13 deletions src/apps/blazor/infrastructure/Themes/CustomTypography.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,103 +8,103 @@ public static class CustomTypography
{
Default = new Default()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = ".875rem",
FontWeight = 400,
LineHeight = 1.43,
LetterSpacing = ".01071em"
},
H1 = new H1()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = "3rem",
FontWeight = 300,
LineHeight = 1.167,
LetterSpacing = "-.01562em"
},
H2 = new H2()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = "2.75rem",
FontWeight = 300,
LineHeight = 1.2,
LetterSpacing = "-.00833em"
},
H3 = new H3()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = "2rem",
FontWeight = 400,
LineHeight = 1.167,
LetterSpacing = "0"
},
H4 = new H4()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = "1.75rem",
FontWeight = 400,
LineHeight = 1.235,
LetterSpacing = ".00735em"
},
H5 = new H5()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = "1.5rem",
FontWeight = 400,
LineHeight = 1.334,
LetterSpacing = "0"
},
H6 = new H6()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = "1.25rem",
FontWeight = 400,
LineHeight = 1.6,
LetterSpacing = ".0075em"
},
Button = new Button()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = ".875rem",
FontWeight = 400,
LineHeight = 1.75,
LetterSpacing = ".02857em"
},
Body1 = new Body1()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = "1rem",
FontWeight = 400,
LineHeight = 1.5,
LetterSpacing = ".00938em"
},
Body2 = new Body2()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = ".875rem",
FontWeight = 400,
LineHeight = 1.43,
LetterSpacing = ".01071em"
},
Caption = new Caption()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = ".75rem",
FontWeight = 200,
LineHeight = 1.66,
LetterSpacing = ".03333em"
},
Subtitle1 = new Subtitle1()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = "1rem",
FontWeight = 400,
LineHeight = 1.57,
LetterSpacing = ".00714em"
},
Subtitle2 = new Subtitle2()
{
FontFamily = new[] { "Montserrat", "Helvetica", "Arial", "sans-serif" },
FontFamily = ["Montserrat", "Helvetica", "Arial", "sans-serif"],
FontSize = ".875rem",
FontWeight = 400,
LineHeight = 1.57,
Expand Down
Loading

0 comments on commit a840da2

Please sign in to comment.