aspnetcore模块转移

This commit is contained in:
陈淳
2023-02-09 19:11:56 +08:00
parent 5867559502
commit 943a7344f6
15 changed files with 108 additions and 21 deletions

View File

@@ -12,23 +12,18 @@ using System.Threading.Tasks;
using Yi.Framework.Core.Const;
using Yi.Framework.Core.CurrentUsers;
namespace Yi.Framework.Core.Extensions
namespace Microsoft.AspNetCore.Builder
{
public static class CurrentUserExtensions
public static class CurrentUserUseExtensions
{
public static IServiceCollection AddCurrentUserServer(this IServiceCollection services)
{
return services.AddScoped<ICurrentUser, CurrentUser>();
}
public static IApplicationBuilder UseCurrentUserServer(this IApplicationBuilder app)
{
return app.UseMiddleware<CurrentUserMiddleware>();
}
}
}
public class CurrentUserMiddleware
{

View File

@@ -9,7 +9,7 @@ using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Exceptions;
namespace Yi.Framework.Core.Extensions
namespace Microsoft.AspNetCore.Builder
{
internal class ExceptionModle

View File

@@ -27,7 +27,8 @@ namespace AspNetCore.Microsoft.AspNetCore.Builder
{
foreach (var k in swaggerModels)
{
c.SwaggerEndpoint(k.url, k.name);
c.SwaggerEndpoint(k.Url, k.Name);
}
}
@@ -38,12 +39,17 @@ namespace AspNetCore.Microsoft.AspNetCore.Builder
}
public class SwaggerModel
{
public SwaggerModel(string name)
{
this.Name = name;
this.Url = "/swagger/v1/swagger.json";
}
public SwaggerModel(string url, string name)
{
this.url = url;
this.name = name;
this.Url = url;
this.Name = name;
}
public string url { get; set; }
public string name { get; set; }
public string Url { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Const;
using Yi.Framework.Core.CurrentUsers;
namespace Microsoft.Extensions.DependencyInjection
{
public static class CurrentUserAddExtensions
{
public static IServiceCollection AddCurrentUserServer(this IServiceCollection services)
{
return services.AddScoped<ICurrentUser, CurrentUser>();
}
}
}

View File

@@ -18,4 +18,8 @@
<Folder Include="Microsoft\Extensions\Hosting\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Core\Yi.Framework.Core.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using StartupModules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.AspNetCore
{
public class YiFrameworkAspNetCoreModule : IStartupModule
{
public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
{
app.UseCurrentUserServer();
}
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
{
services.AddCurrentUserServer();
}
}
}

View File

@@ -38,6 +38,7 @@ namespace Yi.Framework.Core.Helper
return assembly.GetTypes().Where(m => m.IsClass
&& className == null ? true : m.Name == className
&& spaceName == null ? true : m.Namespace == spaceName
&& !m.Name.StartsWith("<>")
).ToList();
}

View File

@@ -1,4 +1,6 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Text.Json;
@@ -6,7 +8,14 @@ namespace Yi.Framework.Core.Helper
{
public class JsonHelper
{
public static string ObjToStr<T>(T obj, string dateTimeFormat)
{
IsoDateTimeConverter timeConverter = new IsoDateTimeConverter()
{
DateTimeFormat = dateTimeFormat
};
return Newtonsoft.Json.JsonConvert.SerializeObject(obj, Formatting.Indented, timeConverter);
}
public static string ObjToStr<T>(T obj)
{
@@ -28,7 +37,7 @@ namespace Yi.Framework.Core.Helper
string result = String.Empty;
try
{
JsonSerializer.Serialize("");
System.Text.Json.JsonSerializer.Serialize("");
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer =
new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(T));
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())

View File

@@ -24,7 +24,7 @@ namespace Yi.Framework.Core
//全局错误,需要靠前,放在此处无效
//app.UseErrorHandlingServer();
app.UseCurrentUserServer();
}
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
@@ -34,7 +34,7 @@ namespace Yi.Framework.Core
//全盘扫描,自动依赖注入
services.AddAutoIocServer();
services.AddCurrentUserServer();
}
}

View File

@@ -79,7 +79,13 @@ namespace Yi.Framework.Ddd.Services
ReflexHelper.SetModelValue(nameof(IEntity<long>.Id), SnowflakeHelper.NextId, entity);
}
}
if (entity is IEntity<Guid> entityForGuidId)
{
if (entityForGuidId.Id == Guid.Empty)
{
ReflexHelper.SetModelValue(nameof(IEntity<long>.Id), new Guid(), entity);
}
}
return Task.FromResult(entity);
}