Skip to content

Commit

Permalink
Publish an event on comment creation for the CMS Kit
Browse files Browse the repository at this point in the history
resolves #5463
  • Loading branch information
yekalkan committed Oct 26, 2020
1 parent 4e792e2 commit 99dbc8d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<ProjectReference Include="..\Volo.CmsKit.Common.Application.Contracts\Volo.CmsKit.Common.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.EventBus\Volo.Abp.EventBus.csproj" />
</ItemGroup>

</Project>
@@ -1,9 +1,11 @@
using Volo.Abp.Modularity;
using Volo.Abp.EventBus;

namespace Volo.CmsKit.Public
{
[DependsOn(
typeof(CmsKitCommonApplicationContractsModule)
typeof(CmsKitCommonApplicationContractsModule),
typeof(AbpEventBusModule)
)]
public class CmsKitPublicApplicationContractsModule : AbpModule
{
Expand Down
@@ -0,0 +1,11 @@
using System;
using Volo.Abp.EventBus;

namespace Volo.CmsKit.Public.Comments
{
[EventName("Volo.CmsKit.Comments.Created")]
public class CreatedCommentEvent
{
public Guid Id { get; set; }
}
}
Expand Up @@ -7,6 +7,8 @@
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Uow;
using Volo.Abp.Users;
using Volo.CmsKit.Comments;
using Volo.CmsKit.Users;
Expand All @@ -18,15 +20,21 @@ public class CommentPublicAppService : ApplicationService, ICommentPublicAppServ
protected CmsKitOptions CmsKitOptions { get; }
protected ICommentRepository CommentRepository { get; }
protected ICmsUserLookupService CmsUserLookupService { get; }
public IDistributedEventBus DistributedEventBus { get; }
public IUnitOfWorkManager UnitOfWorkManager { get; }

public CommentPublicAppService(
ICommentRepository commentRepository,
ICmsUserLookupService cmsUserLookupService,
IDistributedEventBus distributedEventBus,
IUnitOfWorkManager unitOfWorkManager,
IOptions<CmsKitOptions> cmsKitOptions)
{
CmsKitOptions = cmsKitOptions.Value;
CommentRepository = commentRepository;
CmsUserLookupService = cmsUserLookupService;
DistributedEventBus = distributedEventBus;
UnitOfWorkManager = unitOfWorkManager;
}

public virtual async Task<ListResultDto<CommentWithDetailsDto>> GetListAsync(string entityType, string entityId)
Expand Down Expand Up @@ -56,6 +64,14 @@ public virtual async Task<CommentDto> CreateAsync(string entityType, string enti
)
);


await UnitOfWorkManager.Current.SaveChangesAsync();

await DistributedEventBus.PublishAsync(new CreatedCommentEvent
{
Id = comment.Id
});

return ObjectMapper.Map<Comment, CommentDto>(comment);
}

Expand Down

0 comments on commit 99dbc8d

Please sign in to comment.