diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Comment/CommentGetOutputDto.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Comment/CommentGetOutputDto.cs index cd348c86..9cd36d9e 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Comment/CommentGetOutputDto.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Comment/CommentGetOutputDto.cs @@ -5,7 +5,7 @@ using Yi.Framework.Rbac.Application.Contracts.Dtos.User; namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Comment { /// - /// 单返回,返回单条评论即可 + /// 鍗曡繑鍥烇紝杩斿洖鍗曟潯璇勮鍗冲彲 /// public class CommentGetOutputDto : EntityDto { @@ -17,17 +17,17 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Comment /// - /// 用户id联表为用户对象 + /// 鐢ㄦ埛id鑱旇〃涓虹敤鎴峰璞 /// public BbsUserGetOutputDto User { get; set; } /// - /// 根节点的评论id + /// 鏍硅妭鐐圭殑璇勮id /// public Guid RootId { get; set; } /// - /// 被回复的CommentId + /// 琚洖澶嶇殑CommentId /// public Guid ParentId { get; set; } diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/IServices/ICommentService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/IServices/ICommentService.cs index 4b787dab..7837de29 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/IServices/ICommentService.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/IServices/ICommentService.cs @@ -6,8 +6,7 @@ namespace Yi.Framework.Bbs.Application.Contracts.IServices /// /// Comment鏈嶅姟鎶借薄 /// - public interface ICommentService : IYiCrudAppService - { + public interface ICommentService{ /// /// 鍙戣〃璇勮 /// diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Forum/CommentService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Forum/CommentService.cs index c0fc717d..63ab7dbb 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Forum/CommentService.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Forum/CommentService.cs @@ -4,6 +4,8 @@ using Microsoft.AspNetCore.Mvc; using SqlSugar; using Volo.Abp; using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; using Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser; using Yi.Framework.Bbs.Application.Contracts.Dtos.Comment; using Yi.Framework.Bbs.Application.Contracts.IServices; @@ -21,19 +23,11 @@ namespace Yi.Framework.Bbs.Application.Services.Forum /// /// 璇勮 /// - public class CommentService : YiCrudAppService, + public class CommentService : ApplicationService, ICommentService { private readonly ISqlSugarRepository _repository; private readonly BbsUserManager _bbsUserManager; - public CommentService(ForumManager forumManager, ISqlSugarRepository discussRepository, IDiscussService discussService, ISqlSugarRepository CommentRepository, BbsUserManager bbsUserManager) : base(CommentRepository) - { - _forumManager = forumManager; - _discussRepository = discussRepository; - _discussService = discussService; - _repository = CommentRepository; - _bbsUserManager = bbsUserManager; - } private ForumManager _forumManager { get; set; } @@ -42,90 +36,20 @@ namespace Yi.Framework.Bbs.Application.Services.Forum private ISqlSugarRepository _discussRepository { get; set; } private IDiscussService _discussService { get; set; } - /// - /// 鑾峰彇鏀逛富棰樹笅鐨勮瘎璁,缁撴瀯涓轰簩缁村垪琛紝璇ユ煡璇㈡棤鍒嗛〉 - /// Todo: 鍙斁鍏ラ鍩熷眰 - /// - /// - /// - /// - public async Task> GetDiscussIdAsync([FromRoute] Guid discussId, [FromQuery] CommentGetListInputVo input) + + + public async Task Create2Async(CommentCreateInputVo input) { - await _discussService.VerifyDiscussPermissionAsync(discussId); - - var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.Content), x => x.Content.Contains(input.Content)) - .Where(x => x.DiscussId == discussId) - .Includes(x => x.CreateUser) - .ToListAsync(); - - //璇ュ疄浣撻渶瑕佽繘琛岃浆鎹 - - //鍚屾椂涓烘墍鏈夌敤鎴穒d杩涜bbs鐨勬墿灞曞嵆鍙 - List userIds = entities.Where(x => x.CreatorId != null).Select(x => x.CreatorId ?? Guid.Empty).ToList(); - var bbsUserInfoDic = (await _bbsUserManager.GetBbsUserInfoAsync(userIds)).ToDictionary(x => x.Id); - - - - - - //------鏁版嵁鏌ヨ瀹屾垚------ - - - - - - //浠庢牴鐩綍寮濮嬬粍瑁 - //缁撴灉鍒濆鍊硷紝绗竴灞傜瓑浜庡叏閮ㄦ牴鑺傜偣 - var allOutPut = entities.OrderByDescending(x => x.CreationTime).ToList(); - - //鑾峰彇鍏ㄩ噺涓婚璇勮锛 鍏堣幏鍙栭《绾х殑锛屽皢鍏朵粬瀛愮粍鍚堝埌椤剁骇涓嬶紝褰㈡垚涓涓簩缁,鍏堣浆鎴恉to - List allOutoutDto = await MapToGetListOutputDtosAsync(allOutPut); - - //寮濮嬫槧灏勯澶栫敤鎴蜂俊鎭瓧娈 - allOutoutDto?.ForEach(x => x.CreateUser = bbsUserInfoDic[x.CreatorId ?? Guid.Empty].Adapt()); - - //寮濮嬬粍瑁卍to鐨勫眰绾у叧绯 - //灏嗗叏閮ㄦ暟鎹繘琛宧ash - var dic = allOutoutDto.ToDictionary(x => x.Id); - - foreach (var comment in allOutoutDto) - { - //涓嶆槸鏍硅妭鐐癸紝闇瑕佽祴鍊 琚瘎璁鸿呯敤鎴蜂俊鎭瓑 - if (comment.ParentId != Guid.Empty) - { - if (dic.ContainsKey(comment.ParentId)) - { - var parentComment = dic[comment.ParentId]; - comment.CommentedUser = parentComment.CreateUser; - } - else - { - continue; - } - } - //root鎴栬卲arent id锛屾牴鑺傜偣閮芥槸绛変簬0鐨 - var id = comment.RootId; - if (id != Guid.Empty) - { - dic[id].Children.Add(comment); - } - - } - - //瀛愮被闇瑕佹帓搴 - var rootOutoutDto = allOutoutDto.Where(x => x.ParentId == Guid.Empty).ToList(); - rootOutoutDto?.ForEach(x => - { - x.Children = x.Children.OrderByDescending(x => x.CreationTime).ToList(); - - }); - - - - return new PagedResultDto(entities.Count(), rootOutoutDto); + var entity = new CommentAggregateRoot(Guid.Empty); + return new CommentGetOutputDto(); } - + [HttpGet("Create22")] + public async Task Create22Async(CommentCreateInputVo input) + { + var entity = new CommentAggregateRoot(Guid.Empty); + return new CommentGetOutputDto(); + } /// /// 鍙戣〃璇勮 /// @@ -134,24 +58,28 @@ namespace Yi.Framework.Bbs.Application.Services.Forum /// // [Permission("bbs:comment:add")] // [Authorize] - public override async Task CreateAsync(CommentCreateInputVo input) + public async Task CreateAsync(CommentCreateInputVo input) { - var discuess = await _discussRepository.GetFirstAsync(x => x.Id == input.DiscussId); - if (discuess is null) - { - throw new UserFriendlyException(DiscussConst.No_Exist); - } + // var discuess = await _discussRepository.GetFirstAsync(x => x.Id == input.DiscussId); + // if (discuess is null) + // { + // throw new UserFriendlyException(DiscussConst.No_Exist); + // } //涓嶆槸瓒呯骇绠$悊鍛橈紝涓斾富棰樺紑鍚姝㈣瘎璁 - if (discuess.IsDisableCreateComment == true && !CurrentUser.GetPermissions().Contains(UserConst.AdminPermissionCode)) - { - throw new UserFriendlyException("璇ヤ富棰樺凡绂佹璇勮鍔熻兘"); - } + // if (discuess.IsDisableCreateComment == true && !CurrentUser.GetPermissions().Contains(UserConst.AdminPermissionCode)) + // { + // throw new UserFriendlyException("璇ヤ富棰樺凡绂佹璇勮鍔熻兘"); + // } - var entity = await _forumManager.CreateCommentAsync(input.DiscussId, input.ParentId, input.RootId, input.Content); - return await MapToGetOutputDtoAsync(entity); + // var entity = await _forumManager.CreateCommentAsync(input.DiscussId, input.ParentId, input.RootId, input.Content); + var entity = new CommentAggregateRoot(Guid.Empty); + return new CommentGetOutputDto(); } + public CommentService(IRepository repository) + { + } } } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/YiFrameworkRbacDomainModule.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/YiFrameworkRbacDomainModule.cs index a5568c1e..07d3f261 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/YiFrameworkRbacDomainModule.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/YiFrameworkRbacDomainModule.cs @@ -26,11 +26,11 @@ namespace Yi.Framework.Rbac.Domain { var service = context.Services; var configuration = context.Services.GetConfiguration(); - service.AddControllers(options => - { - options.Filters.Add(); - options.Filters.Add(); - }); + // service.AddControllers(options => + // { + // options.Filters.Add(); + // // options.Filters.Add(); + // }); //閰嶇疆闃块噷浜戠煭淇 Configure(configuration.GetSection(nameof(AliyunOptions))); diff --git a/Yi.Abp.Net8/src/Yi.Abp.Application/Services/TestService.cs b/Yi.Abp.Net8/src/Yi.Abp.Application/Services/TestService.cs index 409db5dc..cf9b0089 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Application/Services/TestService.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Application/Services/TestService.cs @@ -21,178 +21,15 @@ namespace Yi.Abp.Application.Services /// public class TestService : ApplicationService { - /// - /// 灞炴ф敞鍏 - /// 涓嶆帹鑽愶紝鍧戝お澶氾紝瀹规槗鎶婅嚜宸辩帺姝伙紝绠鍗曠殑涓滆タ鍙互鐢ㄤ竴鐢 - /// - public ISqlSugarRepository sqlSugarRepository { get; set; } - - private ICommentService _commentService; - public readonly ISqlSugarRepository _commentRepository; - public TestService(ICommentService commentService, ISqlSugarRepository commentRepository) + [HttpGet("hello-world/string")] + public async Task GetHelloWorld1(string? name) { - _commentService = commentService; - _commentRepository = commentRepository; + return "1"; } - - public async Task GetAbpUnitOfWorkMiddleware() + [HttpGet("hello-world/dto")] + public async Task GetHelloWorld2(string? name) { - var entity = new CommentAggregateRoot(Guid.Empty); - entity.Content = "娴嬭瘯"; - entity.ParentId = Guid.Empty; - entity.RootId = Guid.Empty; - await _commentRepository.InsertAsync(entity); - return "yes"; + return new CommentGetOutputDto(); } - - /// - /// 鍔ㄦ丄pi - /// - /// - /// - [HttpGet("hello-world")] - public string GetHelloWorld(string? name) - { - //浼氳嚜鍔ㄦ坊鍔犲墠缂锛岃屼笉鏄噸缃紝鏇寸鍚堜範鎯 - //濡傛灉闇瑕侀噸缃互"/"鏍圭洰褰曞紑澶村嵆鍙 - //浣犲ソ涓栫晫 - return name ?? "HelloWord"; - } - - /// - /// 寮傚父澶勭悊 - /// - /// - [HttpGet("error")] - public string GetError() - { - throw new UserFriendlyException("涓氬姟寮傚父"); - throw new Exception("绯荤粺寮傚父"); - } - - /// - /// SqlSugar - /// - /// - public async Task GetSqlSugarDbAsync() - { - //鐢ㄦ埛浣撻獙浼樺厛锛屽彲鐩存帴浣跨敤Db鎿嶄綔锛屼緷璧栨娊璞 - return await sqlSugarRepository._DbQueryable.ToListAsync(); - } - - /// - /// 宸ヤ綔鍗曞厓 - /// - /// - public async Task GetUowAsync() - { - //榄旀敼 - // 鐢ㄦ埛浣撻獙浼樺厛锛屼竾閲戞补妯″紡锛屾敮鎸侀珮骞跺彂銆傛敮鎸佸崟銆佸绾跨▼骞跺彂瀹夊叏锛屾敮鎸佸绾跨▼宸ヤ綔鍗曞厓锛屾敮鎸佸绾跨▼鏃犲伐浣滃崟鍏冿紝鏀寔銆傘傘 - // 璇锋敞鎰忥紝濡傛灉requiresNew: true鍙湁鍦ㄦ病鏈夊伐浣滃崟鍏冨唴浣跨敤锛屽祵濂楀瓙宸ヤ綔鍗曞厓锛岄粯璁ゅ糵alse鍗冲彲 - // 鑷姩鍦ㄥ悇涓儏鍐靛鐞哾b瀹㈡埛绔渶浼樿В涔嬩竴 - int i = 3; - List tasks = new List(); - await sqlSugarRepository.GetListAsync(); - await sqlSugarRepository.GetListAsync(); - while (i > 0) - { - tasks.Add(Task.Run(async () => - { - await sqlSugarRepository.InsertAsync(new BannerAggregateRoot { Name = "鎻掑叆2" }); - using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true)) - { - await sqlSugarRepository.InsertAsync(new BannerAggregateRoot { Name = "鎻掑叆1" }); - await uow.CompleteAsync(); - } - })); - await sqlSugarRepository.InsertAsync(new BannerAggregateRoot { Name = "鎻掑叆3" }); - i--; - } - - await Task.WhenAll(tasks); - } - - /// - /// 褰撳墠鐢ㄦ埛 - /// - /// - public void GetCurrentUser() - { - //褰搕oken閴存潈涔嬪悗锛屽彲浠ョ洿鎺ヨ幏鍙 - if (CurrentUser.Id is not null) - { - //鏉冮檺 - CurrentUser.GetPermissions(); - - //瑙掕壊淇℃伅 - CurrentUser.GetRoleInfo(); - - //閮ㄩ棬id - CurrentUser.GetDeptId(); - } - } - - /// - /// 鏁版嵁鏉冮檺 - /// - public void GetDataFilter() - { - //杩欓噷浼氭暟鎹潈闄愯繃婊 - using (DataFilter.DisablePermissionHandler()) - { - //杩欓噷涓嶄細鏁版嵁鏉冮檺杩囨护 - } - //杩欓噷浼氭暟鎹潈闄愯繃婊 - } - - /// - /// 瀵硅薄鏄犲皠 - /// - public void GetMapper() - { - //鐩存帴鏃犺剳Adapt锛屾棤闇閰嶇疆 - var entity = new BannerAggregateRoot(); - var dto = entity.Adapt(); - } - - private static int RequestNumber { get; set; } = 0; - /// - /// 閫熺巼闄愬埗 - /// - /// - // [DisableRateLimiting] - //[EnableRateLimiting("sliding")] - public int GetRateLimiting() - { - RequestNumber++; - return RequestNumber; - } - - - public ISettingProvider _settingProvider { get; set; } - - public ISettingManager _settingManager { get; set; } - /// - /// 绯荤粺閰嶇疆妯″潡 - /// - /// - public async Task GetSettingAsync() - { - //DDD闇瑕佹彁鍓嶅畾涔 - //榛樿鏉ヨ锛屼笉鎻愪緵淇敼鎿嶄綔锛岄厤缃簲璇ョ嫭绔 - var enableOrNull = await _settingProvider.GetOrNullAsync("DDD"); - - //濡傛灉瑕佽繘琛屼慨鏀癸紝鍙娇鐢▂i.framework涓嬬殑ISettingManager - await _settingManager.SetGlobalAsync("DDD", "false"); - - var enableOrNull2 = await _settingManager.GetOrNullGlobalAsync("DDD"); - - //褰撶劧锛屼粬鐨勭嫭鐗瑰湴鏂癸紝鏄敮鎸佹潵鑷涓ā鍧楋紝渚嬪閰嶇疆鏂囦欢锛 - var result = await _settingManager.GetOrNullConfigurationAsync("Test"); - - - return result ?? string.Empty; - } - } } diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/AbpUnitOfWorkMiddleware2.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/AbpUnitOfWorkMiddleware2.cs new file mode 100644 index 00000000..ae109f1f --- /dev/null +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/AbpUnitOfWorkMiddleware2.cs @@ -0,0 +1,65 @@ +锘// Decompiled with JetBrains decompiler +// Type: Volo.Abp.AspNetCore.Uow.AbpUnitOfWorkMiddleware +// Assembly: Volo.Abp.AspNetCore, Version=8.2.0.0, Culture=neutral, PublicKeyToken=null +// MVID: E24BDAEE-E92D-4420-84F7-3DD088C817A4 +// Assembly location: C:\Users\Administrator\.nuget\packages\volo.abp.aspnetcore\8.2.0\lib\net8.0\Volo.Abp.AspNetCore.dll +// XML documentation location: C:\Users\Administrator\.nuget\packages\volo.abp.aspnetcore\8.2.0\lib\net8.0\Volo.Abp.AspNetCore.xml + +using Microsoft.AspNetCore.Components.Endpoints; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Options; +using System; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.AspNetCore.Middleware; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Uow; + +#nullable enable +namespace Volo.Abp.AspNetCore.Uow +{ + public class AbpUnitOfWorkMiddleware2 : AbpMiddlewareBase, ITransientDependency + { + private readonly IUnitOfWorkManager _unitOfWorkManager; + private readonly AbpAspNetCoreUnitOfWorkOptions _options; + + public AbpUnitOfWorkMiddleware2( + IUnitOfWorkManager unitOfWorkManager, + IOptions options) + { + this._unitOfWorkManager = unitOfWorkManager; + this._options = options.Value; + } + + public override async Task InvokeAsync(HttpContext context, RequestDelegate next) + { + // await next(context); + // await next(context).ConfigureAwait(false); + if (await ShouldSkipAsync(context, next).ConfigureAwait(false) || IsIgnoredUrl(context)) + { + await next(context).ConfigureAwait(false); + } + else + { + using (IUnitOfWork uow = _unitOfWorkManager.Reserve("_AbpActionUnitOfWork")) + { + await next(context).ConfigureAwait(false); + await uow.CompleteAsync(context.RequestAborted).ConfigureAwait(false); + } + } + } + + private bool IsIgnoredUrl(HttpContext context) + { + return context.Request.Path.Value != null && this._options.IgnoredUrls.Any( + (Func)(x => + context.Request.Path.Value.StartsWith(x, StringComparison.OrdinalIgnoreCase))); + } + + protected override async Task ShouldSkipAsync(HttpContext context, RequestDelegate next) + { + return context.GetEndpoint()?.Metadata?.GetMetadata() != null || + await base.ShouldSkipAsync(context, next).ConfigureAwait(false); + } + } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs index c5bc8565..58897322 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs @@ -48,7 +48,11 @@ try return Task.CompletedTask; }); await next(); - Console.WriteLine("涔嬪悗-----" + id); + if (http.Request.Path.Value.Contains("hello-world")) + { + Console.WriteLine("涔嬪悗-----" + id); + } + }); await app.InitializeApplicationAsync(); await app.RunAsync(); diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/TestService.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/TestService.cs new file mode 100644 index 00000000..7c05e8bd --- /dev/null +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/TestService.cs @@ -0,0 +1,42 @@ +锘縰sing Microsoft.AspNetCore.Mvc; +using Volo.Abp.Application.Services; + +namespace Yi.Abp.Application.Services +{ + /// + /// 甯哥敤榄旀敼鍙婃墿灞曠ず渚 + /// + public class TestService : ApplicationService + { + [HttpGet("hello-world/string")] + public async Task GetHelloWorld1(string? name) + { + return "1"; + } + [HttpGet("hello-world/dto")] + public async Task GetHelloWorld2(string? name) + { + return new CommentGetOutputDto(); + } + } +} + +public class CommentGetOutputDto +{ + + public DateTime? CreateTime { get; set; } + public string Content { get; set; } + + public Guid DiscussId { get; set; } + + /// + /// 鏍硅妭鐐圭殑璇勮id + /// + public Guid RootId { get; set; } + + /// + /// 琚洖澶嶇殑CommentId + /// + public Guid ParentId { get; set; } + +} diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs index 75e540bf..63b5413b 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs @@ -42,14 +42,14 @@ using Yi.Framework.TenantManagement.Application; namespace Yi.Abp.Web { [DependsOn( - typeof(YiAbpSqlSugarCoreModule), - typeof(YiAbpApplicationModule), - typeof(AbpAspNetCoreMultiTenancyModule), + // typeof(YiAbpSqlSugarCoreModule), + // typeof(YiAbpApplicationModule), + // typeof(AbpAspNetCoreMultiTenancyModule), typeof(AbpAspNetCoreMvcModule), typeof(AbpAutofacModule), typeof(AbpSwashbuckleModule), typeof(AbpAspNetCoreSerilogModule), - typeof(AbpAuditingModule), + // typeof(AbpAuditingModule), typeof(AbpAspNetCoreAuthenticationJwtBearerModule), typeof(YiFrameworkAspNetCoreModule), typeof(YiFrameworkAspNetCoreAuthenticationOAuthModule) @@ -63,59 +63,29 @@ namespace Yi.Abp.Web var configuration = context.Services.GetConfiguration(); var host = context.Services.GetHostingEnvironment(); var service = context.Services; - //璇锋眰鏃ュ織 - Configure(optios => - { - //榛樿鍏抽棴锛屽紑鍚細鏈夊ぇ閲忕殑瀹¤鏃ュ織 - optios.IsEnabled = false; - //瀹¤鏃ュ織杩囨护鍣 - optios.AlwaysLogSelectors.Add(x => Task.FromResult(!x.Url.StartsWith("/api/app/file/"))); - }); - //閲囩敤furion鏍煎紡鐨勮鑼冨寲api锛岄粯璁や笉寮鍚紝浣跨敤abp浼橀泤鐨勬柟寮 - //浣犳病鐪嬮敊銆傘傘 - //service.AddFurionUnifyResultApi(); - //閰嶇疆閿欒澶勭悊鏄剧ず璇︽儏 - Configure(options => { options.SendExceptionsDetailsToClients = true; }); //鍔ㄦ丄pi Configure(options => { - options.ConventionalControllers.Create(typeof(YiAbpApplicationModule).Assembly, + options.ConventionalControllers.Create(typeof(YiAbpWebModule).Assembly, options => options.RemoteServiceName = "default"); - options.ConventionalControllers.Create(typeof(YiFrameworkRbacApplicationModule).Assembly, - options => options.RemoteServiceName = "rbac"); - options.ConventionalControllers.Create(typeof(YiFrameworkBbsApplicationModule).Assembly, - options => options.RemoteServiceName = "bbs"); - options.ConventionalControllers.Create(typeof(YiFrameworkChatHubApplicationModule).Assembly, - options => options.RemoteServiceName = "chat-hub"); - options.ConventionalControllers.Create(typeof(YiFrameworkTenantManagementApplicationModule).Assembly, - options => options.RemoteServiceName = "tenant-management"); - options.ConventionalControllers.Create(typeof(YiFrameworkCodeGenApplicationModule).Assembly, - options => options.RemoteServiceName = "code-gen"); + //缁熶竴鍓嶇紑 options.ConventionalControllers.ConventionalControllerSettings.ForEach(x => x.RootPath = "api/app"); }); //璁剧疆api鏍煎紡 - service.AddControllers().AddNewtonsoftJson(options => - { - options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; - options.SerializerSettings.Converters.Add(new StringEnumConverter()); - }); + // service.AddControllers().AddNewtonsoftJson(options => + // { + // options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; + // }); - //璁剧疆缂撳瓨涓嶈杩囨湡锛岄粯璁ゆ粦鍔20鍒嗛挓 - Configure(cacheOptions => - { - cacheOptions.GlobalCacheEntryOptions.SlidingExpiration = null; - //缂撳瓨key鍓嶇紑 - cacheOptions.KeyPrefix = "Yi:"; - }); + - - Configure(options => { options.AutoValidate = false; }); + // Configure(options => { options.AutoValidate = false; }); //Swagger context.Services.AddYiSwaggerGen(options => @@ -124,143 +94,9 @@ namespace Yi.Abp.Web new OpenApiInfo { Title = "Yi.Framework.Abp", Version = "v1", Description = "闆嗗ぇ鎴愯" }); }); - //璺ㄥ煙 - context.Services.AddCors(options => - { - options.AddPolicy(DefaultCorsPolicyName, builder => - { - builder - .WithOrigins( - configuration["App:CorsOrigins"]! - .Split(";", StringSplitOptions.RemoveEmptyEntries) - .Select(o => o.RemovePostFix("/")) - .ToArray() - ) - .WithAbpExposedHeaders() - .SetIsOriginAllowedToAllowWildcardSubdomains() - .AllowAnyHeader() - .AllowAnyMethod() - .AllowCredentials(); - }); - }); - - //閰嶇疆澶氱鎴 - Configure(options => - { - //鍩轰簬cookie jwt涓嶅ソ鐢紝鏈夊潙 - options.TenantResolvers.Clear(); - options.TenantResolvers.Add(new HeaderTenantResolveContributor()); - //options.TenantResolvers.Add(new HeaderTenantResolveContributor()); - //options.TenantResolvers.Add(new CookieTenantResolveContributor()); - - //options.TenantResolvers.RemoveAll(x => x.Name == CookieTenantResolveContributor.ContributorName); - }); - - //閫熺巼闄愬埗 - //姣60绉掗檺鍒100涓姹傦紝婊戝潡娣诲姞锛屽垎6娈 - service.AddRateLimiter(_ => - { - _.RejectionStatusCode = StatusCodes.Status429TooManyRequests; - _.OnRejected = (context, _) => - { - if (context.Lease.TryGetMetadata(MetadataName.RetryAfter, out var retryAfter)) - { - context.HttpContext.Response.Headers.RetryAfter = - ((int)retryAfter.TotalSeconds).ToString(NumberFormatInfo.InvariantInfo); - } - - context.HttpContext.Response.StatusCode = StatusCodes.Status429TooManyRequests; - context.HttpContext.Response.WriteAsync("Too many requests. Please try again later."); - - return new ValueTask(); - }; - - //鍏ㄥ眬浣跨敤锛岄摼寮忚〃杈惧紡 - _.GlobalLimiter = PartitionedRateLimiter.CreateChained( - PartitionedRateLimiter.Create(httpContext => - { - var userAgent = httpContext.Request.Headers.UserAgent.ToString(); - - return RateLimitPartition.GetSlidingWindowLimiter - (userAgent, _ => - new SlidingWindowRateLimiterOptions - { - PermitLimit = 1000, - Window = TimeSpan.FromSeconds(60), - SegmentsPerWindow = 6, - QueueProcessingOrder = QueueProcessingOrder.OldestFirst - }); - })); - }); - - - //jwt閴存潈 - var jwtOptions = configuration.GetSection(nameof(JwtOptions)).Get(); - var refreshJwtOptions = configuration.GetSection(nameof(RefreshJwtOptions)).Get(); - - context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) - .AddJwtBearer(options => - { - options.TokenValidationParameters = new TokenValidationParameters - { - ClockSkew = TimeSpan.Zero, - ValidateIssuerSigningKey = true, - ValidIssuer = jwtOptions.Issuer, - ValidAudience = jwtOptions.Audience, - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtOptions.SecurityKey)) - }; - options.Events = new JwtBearerEvents - { - OnMessageReceived = context => - { - var accessToken = context.Request.Query["access_token"]; - if (!string.IsNullOrEmpty(accessToken)) - { - context.Token = accessToken; - } - - return Task.CompletedTask; - } - }; - }) - .AddJwtBearer(TokenTypeConst.Refresh, options => - { - options.TokenValidationParameters = new TokenValidationParameters - { - ClockSkew = TimeSpan.Zero, - ValidateIssuerSigningKey = true, - ValidIssuer = refreshJwtOptions.Issuer, - ValidAudience = refreshJwtOptions.Audience, - IssuerSigningKey = - new SymmetricSecurityKey(Encoding.UTF8.GetBytes(refreshJwtOptions.SecurityKey)) - }; - options.Events = new JwtBearerEvents - { - OnMessageReceived = context => - { - var refresh_token = context.Request.Headers["refresh_token"]; - if (!string.IsNullOrEmpty(refresh_token)) - { - context.Token = refresh_token; - return Task.CompletedTask; - } - - var refreshToken = context.Request.Query["refresh_token"]; - if (!string.IsNullOrEmpty(refreshToken)) - { - context.Token = refreshToken; - } - - return Task.CompletedTask; - } - }; - }) - .AddQQ(options => { configuration.GetSection("OAuth:QQ").Bind(options); }) - .AddGitee(options => { configuration.GetSection("OAuth:Gitee").Bind(options); }); - - //鎺堟潈 - context.Services.AddAuthorization(); + + return Task.CompletedTask; } @@ -277,30 +113,17 @@ namespace Yi.Abp.Web //璺ㄥ煙 app.UseCors(DefaultCorsPolicyName); - if (!env.IsDevelopment()) - { - //閫熺巼闄愬埗 - app.UseRateLimiter(); - } + - //鏃犳劅token锛屽厛鍒锋柊鍐嶉壌鏉 - app.UseRefreshToken(); - - //閴存潈 app.UseAuthentication(); - //澶氱鎴 - app.UseMultiTenancy(); + //swagger app.UseYiSwagger(); - //娴侀噺璁块棶缁熻,闇redis鏀寔锛屽惁鍒欎笉鐢熸晥 - app.UseAccessLog(); - - //璇锋眰澶勭悊 - app.UseYiApiHandlinge(); + //闈欐佽祫婧 app.UseStaticFiles("/api/app/wwwroot"); @@ -308,15 +131,12 @@ namespace Yi.Abp.Web app.UseDirectoryBrowser("/api/app/wwwroot"); - // app.Properties.Add("_AbpExceptionHandlingMiddleware_Added",false); //宸ヤ綔鍗曞厓 app.UseUnitOfWork(); //鎺堟潈 app.UseAuthorization(); - //瀹¤鏃ュ織 - app.UseAuditing(); //鏃ュ織璁板綍 app.UseAbpSerilogEnrichers();