Open Closed

CMS Kit Page entity and MediaDescriptor entity are protected type, and also CoverImageMediaId which is column of BlogsPost entity cannot be created with data seeder #1942


User avatar
0
ElifKaya created

Hello,

We pull the CMS kit from the ABP Suite and we use it as a module in our project. We want to create default data as it is in the CmsKitDataSeedContributor.cs. But we can not insert Page and MediaDescriptor data because these entites are protected type. And also, we want to insert image to BlogsPost data but we can not create CoverImageMediaId with using data seeder. CoverImageMediaId can be created from only BlogPosts CRUD View.

Can you help us about this problem?

Thanks,

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

If you're creating a bug/problem report, please include followings:

  • ABP Framework version: v4.4.3
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes / no
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

1 Answer(s)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Hi @ElifKaya,

    Some of entities can not be created without a domain logic, DDD aims to keep domain integrity. So, you have to create them with their own Manager. For example, you can create a Page with the PageManager. See example below:

        public class MyDataSeedContributor : IDataSeedContributor, ITransientDependency
        {
            private readonly PageManager _pageManager;
            private readonly IPageRepository _pageRepository;
    
            public MyDataSeedContributor(PageManager pageManager, IPageRepository pageRepository)
            {
                _pageManager = pageManager;
                _pageRepository = pageRepository;
            }
    
            public async Task SeedAsync(DataSeedContext context)
            {
                var page = await _pageManager.CreateAsync("Hello World", "hello-world", "Some long content");
    
                await _pageRepository.InsertAsync(page);
            }
        }
    

    Inject Manager class of entity with inaccessible constructor and create them with Manager.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11