abp icon indicating copy to clipboard operation
abp copied to clipboard

Use of CMS kit in Own module

Open vnetonline opened this issue 2 years ago • 8 comments

I want to use the cmskit commenting subsystem in a issue tracking module which I have developed but the documentation is not clear on how to use the commenting system ….. my module will be dependant on cmskit do I meet to include the nugget package of cmskit in my module ??

vnetonline avatar Jul 28 '22 00:07 vnetonline

In order to use the Comment Sub System I have referenced the Volo.Cmskit.Common.Application in my Amazing.Software.IssueTracking.Application

image

and added the following to my IssueTrackingApplicationModule

image

is my approach right ?

vnetonline avatar Jul 28 '22 12:07 vnetonline

Hi @vnetonline

Common packages include only common logic between CmsKit.Admin and CmsKit.Public packages and mostly don't include business logic inside it.

If you want to use comments in your public website (users can comment some contents in your application), you can use CmsKit.Public packages.

  • Install CmsKit.Public.* packages to your each layer.
  • You should enable it
    GlobalFeatureManager.Instance.Modules.CmsKit(cmsKit =>
    {
        cmsKit.Comments.Enable();
    });
    

You can follow this documentation for installing & enabling CmsKit

  • You should create a new migration and apply it before starting to use CmsKit.

  • After successfully completing installing & enabling processes, you should mark an entity name as commendable, let say it's Product

    Configure<CmsKitCommentOptions>(options =>
    {
        options.EntityTypes.Add(new CommentEntityTypeDefinition("Product"));
    });
    
  • Then you can place anywhere a commenting section like that:

    @await Component.InvokeAsync(typeof(CommentingViewComponent), new
    {
      entityType = "Product",
      entityId = "123"
    })
    

Please follow CmsKit: Comments documentation for advanced usage scenarios

enisn avatar Aug 01 '22 08:08 enisn

my question is how i use it in my module

vnetonline avatar Aug 01 '22 10:08 vnetonline

Your module can still depend on the CMS Kit packages like a regular application.

In order to use the Comment Sub System I have referenced the Volo.Cmskit.Common.Application in my Amazing.Software.IssueTracking.Application

image ...

In that image I see Volo.CmsKit.Common.Application package, that's why I'm suggesting installing Admin or Public packages of Cms Kit.

If you want to add a new comment from code, you should use Volo.CmsKit.Public packages and you can use AppServices of CmsKit like this:


public class YourAppService : ApplicationService
{
  public ICommentPublicAppService CommentPublicAppService { get; }
  public YourAppService(ICommentPublicAppService commentPublicAppService)
  {
    CommentPublicAppService = commentPublicAppService 
  }

  public async Task DoSomethingAsync(SomeDto dto)
  {
    // ...
    var comment = await CommentPublicAppService.CreateAsync("MyEntity", dto.Id, new CreateCommentInput
    {
        Text = "Hello World!"
    });
  
    // do something with comment.
  }
}

enisn avatar Aug 01 '22 12:08 enisn

... image

is my approach right ?

As an answer for that, I strongly suggest to you, depending your project on CmsKit Public packages instead of Common packages. And rest of your approach seems right 👍

enisn avatar Aug 01 '22 12:08 enisn

@enisn

I think the documentation is wrong then

image

the document states to put the Definitions in the *.Domain or *.Domain.Shared project but the domain projects don't reference the *.Application.Contracts module so you can't create, update and delete policies.

vnetonline avatar Aug 02 '22 02:08 vnetonline

You have to add a complete reference to your projects like below:

This is a basic dependency scheme

  • Volo.Abp.CmsKit.Domain -> YourProjectName.Domain
  • Volo.Abp.CmsKit.Domain.Shared -> YourProjectName.Domain.Shared
  • Volo.Abp.CmsKit.MongoDB -> YourProjectName.MongoDB
  • Volo.Abp.CmsKit.EntityFrameworkCore -> YourProjectName.EntityFrameworkCore
  • Volo.CmsKit.HttpApi.Client -> YourProjectName.HttpApi.Client
  • Volo.CmsKit.HttpApi -> YourProjectName.HttpApi
  • Volo.CmsKit.Public.Application -> YourProjectName.Application
  • Volo.CmsKit.Public.Application.Contracts -> YourProjectName.Application.Contracts
  • Volo.CmsKit.Web -> YourProjectName.Web

Each layer should depend on the same layer of CmsKit.

I mentioned before, If you don't need Admin related codes, you can just add only Volo.CmsKit.Public.* package references.

enisn avatar Aug 02 '22 07:08 enisn

Thanks for your reply @enisn I get what you are suggesting, however, if add Volo.Abp.CmsKit.EntityFrameworkCore -> YourProjectName.EntityFrameworkCore reference to my module ... will my module also install the migrations for CmsKit?

vnetonline avatar Aug 04 '22 05:08 vnetonline

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 15 '22 18:10 stale[bot]