零度框架 1.0 版本正式发布,共 184 项改进。

This commit is contained in:
administrator committed 2024-05-31 12:28:02 +08:00
1 parent c14a872b77
commit baf06cd88f
182 files changed
+2537 -1613

No files matched your search

@@ -1,4 +1,7 @@
using HelloShop.ServiceDefaults.Permissions;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using HelloShop.ServiceDefaults.Permissions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization.Infrastructure;
using Microsoft.Extensions.Options;
@@ -0,0 +1,13 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Distributed;
namespace HelloShop.ServiceDefaults.Authorization
{
public class FakePermissionChecker(IHttpContextAccessor httpContextAccessor, IDistributedCache distributedCache) : PermissionChecker(httpContextAccessor, distributedCache)
{
public override Task<bool> IsGrantedAsync(int roleId, string permissionName, string? resourceType = null, string? resourceId = null) => Task.FromResult(true);
}
}
@@ -1,7 +1,7 @@
using HelloShop.ServiceDefaults.Constants;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Reflection.Metadata.Ecma335;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using HelloShop.ServiceDefaults.Constants;
namespace HelloShop.ServiceDefaults.Authorization;
@@ -1,4 +1,7 @@
using System.Security.Claims;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using System.Security.Claims;
namespace HelloShop.ServiceDefaults.Authorization;
@@ -1,4 +1,7 @@
using HelloShop.ServiceDefaults.Constants;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using HelloShop.ServiceDefaults.Constants;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Distributed;
using System.Security.Claims;
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Authorization;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Authorization;
public class PermissionGrantCacheItem(bool isGranted = false)
{
@@ -1,4 +1,7 @@
using Microsoft.AspNetCore.Authorization;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization.Infrastructure;
namespace HelloShop.ServiceDefaults.Authorization;
@@ -9,7 +12,7 @@ public class PermissionRequirementHandler(IPermissionChecker permissionChecker)
{
if (context.Resource is IAuthorizationResource resource)
{
if (await permissionChecker.IsGrantedAsync(context.User,requirement.Name, resource.ResourceType, resource.ResourceId))
if (await permissionChecker.IsGrantedAsync(context.User, requirement.Name, resource.ResourceType, resource.ResourceId))
{
context.Succeed(requirement);
}
@@ -21,7 +24,7 @@ public class PermissionRequirementHandler(IPermissionChecker permissionChecker)
return;
}
if(await permissionChecker.IsGrantedAsync(context.User,requirement.Name))
if (await permissionChecker.IsGrantedAsync(context.User, requirement.Name))
{
context.Succeed(requirement);
return;
@@ -1,11 +1,11 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
using System.Net.Http.Headers;
using System.Net.Http.Json;
namespace HelloShop.ServiceDefaults.Authorization;
@@ -23,6 +23,7 @@ public class RemotePermissionChecker(IHttpContextAccessor httpContextAccessor, I
Dictionary<string, string?> parameters = new()
{
{ nameof(roleId), roleId.ToString() },
{ nameof(permissionName), permissionName },
{ nameof(resourceType) , resourceType },
{ nameof(resourceId), resourceId }
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Authorization;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Authorization;
public record struct ResourceInfo(string ResourceType, string ResourceId) : IAuthorizationResource
{
@@ -1,6 +1,9 @@
namespace HelloShop.ServiceDefaults.Constants;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Constants;
public static class CustomClaimTypes
{
public const string RoleIdentifier = "roleid";
public const string RoleIdentifier = "roleid";
}
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Constants;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Constants;
public static class EntityConnstants
{
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Constants;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Constants;
public static class IdentityConstants
{
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Constants;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Constants;
public class PagingConstants
{
+10 -19
View File
@@ -1,14 +1,20 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using OpenTelemetry.Logs;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
namespace Microsoft.Extensions.Hosting;
// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
// This project should be referenced by each service project in your solution.
// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
public static class Extensions
{
public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder)
@@ -25,7 +31,7 @@ public static class Extensions
http.AddStandardResilienceHandler();
// Turn on service discovery by default
http.UseServiceDiscovery();
http.AddServiceDiscovery();
});
return builder;
@@ -48,12 +54,6 @@ public static class Extensions
})
.WithTracing(tracing =>
{
if (builder.Environment.IsDevelopment())
{
// We want to view all traces in development
tracing.SetSampler(new AlwaysOnSampler());
}
tracing.AddAspNetCoreInstrumentation()
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
//.AddGrpcClientInstrumentation()
@@ -71,15 +71,9 @@ public static class Extensions
if (useOtlpExporter)
{
builder.Services.Configure<OpenTelemetryLoggerOptions>(logging => logging.AddOtlpExporter());
builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter());
builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter());
builder.Services.AddOpenTelemetry().UseOtlpExporter();
}
// Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package)
// builder.Services.AddOpenTelemetry()
// .WithMetrics(metrics => metrics.AddPrometheusExporter());
// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
//{
@@ -101,9 +95,6 @@ public static class Extensions
public static WebApplication MapDefaultEndpoints(this WebApplication app)
{
// Uncomment the following line to enable the Prometheus endpoint (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package)
// app.MapPrometheusScrapingEndpoint();
// Adding health checks endpoints to applications in non-development environments has security implications.
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
if (app.Environment.IsDevelopment())
@@ -120,4 +111,4 @@ public static class Extensions
return app;
}
}
}
@@ -1,4 +1,6 @@
using Microsoft.Extensions.Caching.Distributed;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using System.Text.Json;
namespace Microsoft.Extensions.Caching.Distributed;
@@ -1,12 +1,10 @@
using HelloShop.ServiceDefaults.Infrastructure;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using HelloShop.ServiceDefaults.Infrastructure;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace HelloShop.ServiceDefaults.Extensions
{
@@ -27,7 +25,7 @@ namespace HelloShop.ServiceDefaults.Extensions
{
using var serviceScope = app.ApplicationServices.CreateScope();
var dataSeedingProviders = serviceScope.ServiceProvider.GetServices<IDataSeedingProvider>().OrderBy(x=>x.Order);
var dataSeedingProviders = serviceScope.ServiceProvider.GetServices<IDataSeedingProvider>().OrderBy(x => x.Order);
foreach (var dataSeedingProvider in dataSeedingProviders)
{
@@ -1,4 +1,7 @@
using FluentValidation;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using FluentValidation;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
@@ -32,17 +35,17 @@ public static class LocalizationExtensions
ValidatorOptions.Global.DisplayNameResolver = (type, memberInfo, lambdaExpression) =>
{
string displayName = memberInfo.Name;
DisplayAttribute? displayAttribute = memberInfo.GetCustomAttribute<DisplayAttribute>(true);
displayName = displayAttribute?.Name ?? displayName;
DisplayNameAttribute? displayNameAttribute = memberInfo.GetCustomAttribute<DisplayNameAttribute>(true);
displayName = displayNameAttribute?.DisplayName ?? displayName;
var localizer = localizerFactory.Create(type);
return localizer[displayName];
};
@@ -1,4 +1,7 @@
using FluentValidation;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using FluentValidation;
using FluentValidation.AspNetCore;
using HelloShop.ServiceDefaults.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
@@ -9,13 +9,7 @@ using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;
using Swashbuckle.AspNetCore.SwaggerUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace HelloShop.ServiceDefaults.Extensions
{
@@ -1,4 +1,7 @@
using HelloShop.ServiceDefaults.Authorization;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using HelloShop.ServiceDefaults.Authorization;
using HelloShop.ServiceDefaults.Permissions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
@@ -1,4 +1,7 @@
using HelloShop.ServiceDefaults.Constants;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using HelloShop.ServiceDefaults.Constants;
using HelloShop.ServiceDefaults.Models.Paging;
using System.Linq.Expressions;
using System.Reflection;
@@ -1,4 +1,7 @@
using System.Collections.Concurrent;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using System.Collections.Concurrent;
using System.Linq.Expressions;
namespace HelloShop.ServiceDefaults.Extensions;
@@ -1,24 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0-preview.3.24209.3" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0-preview.3.24210.17" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
<ItemGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.5.0" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="8.0.1" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.8.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\OpenApi\Custom.css" />
</ItemGroup>
</Project>
@@ -1,4 +1,7 @@
using Microsoft.Net.Http.Headers;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using Microsoft.Net.Http.Headers;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Infrastructure;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Infrastructure;
public class CustomFluentValidationLanguageManager : FluentValidation.Resources.LanguageManager
{
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Infrastructure
{
@@ -1,4 +1,7 @@
using System.Text.Json;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using System.Text.Json;
namespace HelloShop.ServiceDefaults;
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Models.Paging;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Models.Paging;
public class KeywordSearchRequest : PagedAndSortedRequest
{
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Models.Paging;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Models.Paging;
public class PagedAndSortedRequest : PagedRequest
{
@@ -1,4 +1,7 @@
using HelloShop.ServiceDefaults.Constants;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using HelloShop.ServiceDefaults.Constants;
namespace HelloShop.ServiceDefaults.Models.Paging;
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Models.Paging;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Models.Paging;
public class PagedResponse<T>(IReadOnlyList<T> items, int totalCount)
{
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Permissions;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Permissions;
public class PermissionDefinitionResponse
{
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Permissions;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Permissions;
public class PermissionGroupDefinitionResponse
{
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Permissions;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Permissions;
public interface IPermissionDefinitionManager
{
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Permissions;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Permissions;
public interface IPermissionDefinitionProvider
{
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Permissions;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Permissions;
public class PermissionDefinition
{
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Permissions;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Permissions;
public class PermissionDefinitionContext
{
@@ -1,4 +1,6 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using Microsoft.Extensions.DependencyInjection;
namespace HelloShop.ServiceDefaults.Permissions;
@@ -1,4 +1,7 @@
namespace HelloShop.ServiceDefaults.Permissions;
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace HelloShop.ServiceDefaults.Permissions;
public class PermissionGroupDefinition
{
File diff suppressed because it is too large. Load diff