From 0c0e07261c61064ea813524c613f9a133217abfe Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Wed, 2 Feb 2022 15:23:59 +0300 Subject: [PATCH] Blogging: Update service injection property types as protected --- .../Volo/Blogging/Blogs/BlogAppService.cs | 10 +-- .../Blogging/Comments/CommentAppService.cs | 28 ++++---- .../Comments/CommentAuthorizationHandler.cs | 8 +-- .../Volo/Blogging/Posts/PostAppService.cs | 64 +++++++++---------- .../Posts/PostAuthorizationHandler.cs | 8 +-- .../Volo/Blogging/Tagging/TagAppService.cs | 6 +- 6 files changed, 61 insertions(+), 63 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs index ccc1002657..ee379959dc 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Blogs/BlogAppService.cs @@ -11,16 +11,16 @@ namespace Volo.Blogging.Blogs { public class BlogAppService : BloggingAppServiceBase, IBlogAppService { - private readonly IBlogRepository _blogRepository; + protected IBlogRepository BlogRepository { get; } public BlogAppService(IBlogRepository blogRepository) { - _blogRepository = blogRepository; + BlogRepository = blogRepository; } public async Task> GetListAsync() { - var blogs = await _blogRepository.GetListAsync(); + var blogs = await BlogRepository.GetListAsync(); return new ListResultDto( ObjectMapper.Map, List>(blogs) @@ -31,7 +31,7 @@ namespace Volo.Blogging.Blogs { Check.NotNullOrWhiteSpace(shortName, nameof(shortName)); - var blog = await _blogRepository.FindByShortNameAsync(shortName); + var blog = await BlogRepository.FindByShortNameAsync(shortName); if (blog == null) { @@ -43,7 +43,7 @@ namespace Volo.Blogging.Blogs public async Task GetAsync(Guid id) { - var blog = await _blogRepository.GetAsync(id); + var blog = await BlogRepository.GetAsync(id); return ObjectMapper.Map(blog); } diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs index 0b36f8ec37..21daa5c3d3 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs @@ -13,15 +13,13 @@ namespace Volo.Blogging.Comments { public class CommentAppService : BloggingAppServiceBase, ICommentAppService { - protected IBlogUserLookupService UserLookupService; + protected IBlogUserLookupService UserLookupService { get; } - private readonly ICommentRepository _commentRepository; - private readonly IGuidGenerator _guidGenerator; + protected ICommentRepository CommentRepository { get; } - public CommentAppService(ICommentRepository commentRepository, IGuidGenerator guidGenerator, IBlogUserLookupService userLookupService) + public CommentAppService(ICommentRepository commentRepository, IBlogUserLookupService userLookupService) { - _commentRepository = commentRepository; - _guidGenerator = guidGenerator; + CommentRepository = commentRepository; UserLookupService = userLookupService; } @@ -74,7 +72,7 @@ namespace Volo.Blogging.Comments private async Task> GetListOfPostAsync(Guid postId) { - var comments = await _commentRepository.GetListOfPostAsync(postId); + var comments = await CommentRepository.GetListOfPostAsync(postId); return new List( ObjectMapper.Map, List>(comments)); @@ -83,9 +81,9 @@ namespace Volo.Blogging.Comments [Authorize] public async Task CreateAsync(CreateCommentDto input) { - var comment = new Comment(_guidGenerator.Create(), input.PostId, input.RepliedCommentId, input.Text); + var comment = new Comment(GuidGenerator.Create(), input.PostId, input.RepliedCommentId, input.Text); - comment = await _commentRepository.InsertAsync(comment); + comment = await CommentRepository.InsertAsync(comment); await CurrentUnitOfWork.SaveChangesAsync(); @@ -95,14 +93,14 @@ namespace Volo.Blogging.Comments [Authorize] public async Task UpdateAsync(Guid id, UpdateCommentDto input) { - var comment = await _commentRepository.GetAsync(id); + var comment = await CommentRepository.GetAsync(id); await AuthorizationService.CheckAsync(comment, CommonOperations.Update); comment.SetText(input.Text); comment.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp); - comment = await _commentRepository.UpdateAsync(comment); + comment = await CommentRepository.UpdateAsync(comment); return ObjectMapper.Map(comment); } @@ -110,17 +108,17 @@ namespace Volo.Blogging.Comments [Authorize] public async Task DeleteAsync(Guid id) { - var comment = await _commentRepository.GetAsync(id); + var comment = await CommentRepository.GetAsync(id); await AuthorizationService.CheckAsync(comment, CommonOperations.Delete); - await _commentRepository.DeleteAsync(id); + await CommentRepository.DeleteAsync(id); - var replies = await _commentRepository.GetRepliesOfComment(id); + var replies = await CommentRepository.GetRepliesOfComment(id); foreach (var reply in replies) { - await _commentRepository.DeleteAsync(reply.Id); + await CommentRepository.DeleteAsync(reply.Id); } } } diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAuthorizationHandler.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAuthorizationHandler.cs index 9771d136b3..27cad6f5bc 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAuthorizationHandler.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAuthorizationHandler.cs @@ -8,11 +8,11 @@ namespace Volo.Blogging.Comments { public class CommentAuthorizationHandler : AuthorizationHandler { - private readonly IPermissionChecker _permissionChecker; + protected IPermissionChecker PermissionChecker { get; } public CommentAuthorizationHandler(IPermissionChecker permissionChecker) { - _permissionChecker = permissionChecker; + PermissionChecker = permissionChecker; } protected async override Task HandleRequirementAsync( @@ -40,7 +40,7 @@ namespace Volo.Blogging.Comments return true; } - if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Comments.Delete)) + if (await PermissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Comments.Delete)) { return true; } @@ -55,7 +55,7 @@ namespace Volo.Blogging.Comments return true; } - if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Comments.Update)) + if (await PermissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Comments.Update)) { return true; } diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs index a886649104..457656291f 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs @@ -19,11 +19,11 @@ namespace Volo.Blogging.Posts { protected IBlogUserLookupService UserLookupService { get; } - private readonly IPostRepository _postRepository; - private readonly ITagRepository _tagRepository; - private readonly ICommentRepository _commentRepository; - private readonly IDistributedCache> _postsCache; - private readonly ILocalEventBus _localEventBus; + protected IPostRepository PostRepository { get; } + protected ITagRepository TagRepository { get; } + protected ICommentRepository CommentRepository { get; } + protected IDistributedCache> PostsCache { get; } + protected ILocalEventBus LocalEventBus { get; } public PostAppService( IPostRepository postRepository, @@ -35,17 +35,17 @@ namespace Volo.Blogging.Posts ) { UserLookupService = userLookupService; - _postRepository = postRepository; - _tagRepository = tagRepository; - _commentRepository = commentRepository; - _postsCache = postsCache; - _localEventBus = localEventBus; + PostRepository = postRepository; + TagRepository = tagRepository; + CommentRepository = commentRepository; + PostsCache = postsCache; + LocalEventBus = localEventBus; } public async Task> GetListByBlogIdAndTagNameAsync(Guid id, string tagName) { - var posts = await _postRepository.GetPostsByBlogId(id); - var tag = tagName.IsNullOrWhiteSpace() ? null : await _tagRepository.FindByNameAsync(id, tagName); + var posts = await PostRepository.GetPostsByBlogId(id); + var tag = tagName.IsNullOrWhiteSpace() ? null : await TagRepository.FindByNameAsync(id, tagName); var userDictionary = new Dictionary(); var postDtos = new List(ObjectMapper.Map, List>(posts)); @@ -84,7 +84,7 @@ namespace Volo.Blogging.Posts public async Task> GetTimeOrderedListAsync(Guid blogId) { - var postCacheItems = await _postsCache.GetOrAddAsync( + var postCacheItems = await PostsCache.GetOrAddAsync( blogId.ToString(), async () => await GetTimeOrderedPostsAsync(blogId), () => new DistributedCacheEntryOptions @@ -112,7 +112,7 @@ namespace Volo.Blogging.Posts public async Task GetForReadingAsync(GetPostInput input) { - var post = await _postRepository.GetPostByUrl(input.BlogId, input.Url); + var post = await PostRepository.GetPostByUrl(input.BlogId, input.Url); post.IncreaseReadCount(); @@ -132,7 +132,7 @@ namespace Volo.Blogging.Posts public async Task GetAsync(Guid id) { - var post = await _postRepository.GetAsync(id); + var post = await PostRepository.GetAsync(id); var postDto = ObjectMapper.Map(post); @@ -151,22 +151,22 @@ namespace Volo.Blogging.Posts [Authorize(BloggingPermissions.Posts.Delete)] public async Task DeleteAsync(Guid id) { - var post = await _postRepository.GetAsync(id); + var post = await PostRepository.GetAsync(id); await AuthorizationService.CheckAsync(post, CommonOperations.Delete); var tags = await GetTagsOfPostAsync(id); - await _tagRepository.DecreaseUsageCountOfTagsAsync(tags.Select(t => t.Id).ToList()); - await _commentRepository.DeleteOfPost(id); + await TagRepository.DecreaseUsageCountOfTagsAsync(tags.Select(t => t.Id).ToList()); + await CommentRepository.DeleteOfPost(id); - await _postRepository.DeleteAsync(id); + await PostRepository.DeleteAsync(id); await PublishPostChangedEventAsync(post.BlogId); } [Authorize(BloggingPermissions.Posts.Update)] public async Task UpdateAsync(Guid id, UpdatePostDto input) { - var post = await _postRepository.GetAsync(id); + var post = await PostRepository.GetAsync(id); input.Url = await RenameUrlIfItAlreadyExistAsync(input.BlogId, input.Url, post); @@ -179,7 +179,7 @@ namespace Volo.Blogging.Posts post.Description = input.Description; post.CoverImage = input.CoverImage; - post = await _postRepository.UpdateAsync(post); + post = await PostRepository.UpdateAsync(post); var tagList = SplitTags(input.Tags); await SaveTags(tagList, post); @@ -205,7 +205,7 @@ namespace Volo.Blogging.Posts Description = input.Description }; - await _postRepository.InsertAsync(post); + await PostRepository.InsertAsync(post); var tagList = SplitTags(input.Tags); await SaveTags(tagList, post); @@ -216,14 +216,14 @@ namespace Volo.Blogging.Posts private async Task> GetTimeOrderedPostsAsync(Guid blogId) { - var posts = await _postRepository.GetOrderedList(blogId); + var posts = await PostRepository.GetOrderedList(blogId); return ObjectMapper.Map, List>(posts); } private async Task RenameUrlIfItAlreadyExistAsync(Guid blogId, string url, Post existingPost = null) { - if (await _postRepository.IsPostUrlInUseAsync(blogId, url, existingPost?.Id)) + if (await PostRepository.IsPostUrlInUseAsync(blogId, url, existingPost?.Id)) { return url + "-" + Guid.NewGuid().ToString().Substring(0, 5); } @@ -242,7 +242,7 @@ namespace Volo.Blogging.Posts { foreach (var oldTag in post.Tags.ToList()) { - var tag = await _tagRepository.GetAsync(oldTag.TagId); + var tag = await TagRepository.GetAsync(oldTag.TagId); var oldTagNameInNewTags = newTags.FirstOrDefault(t => t == tag.Name); @@ -251,7 +251,7 @@ namespace Volo.Blogging.Posts post.RemoveTag(oldTag.TagId); tag.DecreaseUsageCount(); - await _tagRepository.UpdateAsync(tag); + await TagRepository.UpdateAsync(tag); } else { @@ -262,7 +262,7 @@ namespace Volo.Blogging.Posts private async Task AddNewTags(IEnumerable newTags, Post post) { - var tags = await _tagRepository.GetListAsync(post.BlogId); + var tags = await TagRepository.GetListAsync(post.BlogId); foreach (var newTag in newTags) { @@ -270,12 +270,12 @@ namespace Volo.Blogging.Posts if (tag == null) { - tag = await _tagRepository.InsertAsync(new Tag(GuidGenerator.Create(), post.BlogId, newTag, 1)); + tag = await TagRepository.InsertAsync(new Tag(GuidGenerator.Create(), post.BlogId, newTag, 1)); } else { tag.IncreaseUsageCount(); - tag = await _tagRepository.UpdateAsync(tag); + tag = await TagRepository.UpdateAsync(tag); } post.AddTag(tag.Id); @@ -284,9 +284,9 @@ namespace Volo.Blogging.Posts private async Task> GetTagsOfPostAsync(Guid id) { - var tagIds = (await _postRepository.GetAsync(id)).Tags; + var tagIds = (await PostRepository.GetAsync(id)).Tags; - var tags = await _tagRepository.GetListAsync(tagIds.Select(t => t.TagId)); + var tags = await TagRepository.GetListAsync(tagIds.Select(t => t.TagId)); return ObjectMapper.Map, List>(tags); } @@ -309,7 +309,7 @@ namespace Volo.Blogging.Posts private async Task PublishPostChangedEventAsync(Guid blogId) { - await _localEventBus.PublishAsync( + await LocalEventBus.PublishAsync( new PostChangedEvent { BlogId = blogId diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAuthorizationHandler.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAuthorizationHandler.cs index 7c6033f4b2..83d54e937a 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAuthorizationHandler.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAuthorizationHandler.cs @@ -8,11 +8,11 @@ namespace Volo.Blogging.Posts { public class PostAuthorizationHandler : AuthorizationHandler { - private readonly IPermissionChecker _permissionChecker; + protected IPermissionChecker PermissionChecker { get; } public PostAuthorizationHandler(IPermissionChecker permissionChecker) { - _permissionChecker = permissionChecker; + PermissionChecker = permissionChecker; } protected async override Task HandleRequirementAsync( @@ -40,7 +40,7 @@ namespace Volo.Blogging.Posts return true; } - if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Posts.Delete)) + if (await PermissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Posts.Delete)) { return true; } @@ -55,7 +55,7 @@ namespace Volo.Blogging.Posts return true; } - if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Posts.Update)) + if (await PermissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Posts.Update)) { return true; } diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Tagging/TagAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Tagging/TagAppService.cs index 440d245946..9f82cb1844 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Tagging/TagAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Tagging/TagAppService.cs @@ -8,16 +8,16 @@ namespace Volo.Blogging.Tagging { public class TagAppService : BloggingAppServiceBase, ITagAppService { - private readonly ITagRepository _tagRepository; + protected ITagRepository TagRepository { get; } public TagAppService(ITagRepository tagRepository) { - _tagRepository = tagRepository; + TagRepository = tagRepository; } public async Task> GetPopularTagsAsync(Guid blogId, GetPopularTagsInput input) { - var postTags = (await _tagRepository.GetListAsync(blogId)).OrderByDescending(t=>t.UsageCount) + var postTags = (await TagRepository.GetListAsync(blogId)).OrderByDescending(t=>t.UsageCount) .WhereIf(input.MinimumPostCount != null, t=>t.UsageCount >= input.MinimumPostCount) .Take(input.ResultCount).ToList();