ABP 依賴注入不了 Can't create component 'xxx.xxx.xxx' as it has dependencies to be satisfied


原文:
https://www.cnblogs.com/senyier/p/7298847.html



報錯:

An unhandled exception occurred while processing the request.
HandlerException: Can't create component 'BIMMP.OAMS.OAContractSealAppService' as it has dependencies to be satisfied.

'BIMMP.OAMS.OAContractSealAppService' is waiting for the following dependencies:
- Service 'Abp.Domain.Repositories.IRepository`2[[BIMMP.OAMS.OAContractSeal, BIMMP.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' which was not registered.
Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency()



原因:

BIMMPDbContext 中忘了加這句 public virtual DbSet<OAContractSeal> OAContractSeals { get; set; }

總結:

數據庫里面也有那張表,估計是誰提交代碼的時候,把那句代碼給沖掉了

全部代碼:

IOAContractSealAppService.cs

namespace BIMMP.OAMS
{
    public interface IOAContractSealAppService : IApplicationService
    {
       
    }
}

OAContractSealAppService.cs

namespace BIMMP.OAMS
{
    [AbpAuthorize]
    public class OAContractSealAppService : BIMMPAppServiceBase, IOAContractSealAppService
    {
        private readonly IRepository<OAContractSeal, int> _oAContractSealRepository;

        public OAContractSealAppService(
        IRepository<OAContractSeal, int> oAContractSealRepository)
        {
            _oAContractSealRepository = oAContractSealRepository;
        }
    }
}

BIMMPDbContext.cs

namespace BIMMP.EntityFrameworkCore
{
    public class BIMMPDbContext : AbpZeroDbContext<Tenant, Role, User, BIMMPDbContext>
    {
        public virtual DbSet<OAContractSeal> OAContractSeals { get; set; }
        public BIMMPDbContext(DbContextOptions<BIMMPDbContext> options)
            : base(options)
        {
        }
    }
}

OAContractSeal.cs

namespace BIMMP.OAMS
{
    [Table("OAContractSeal")]
    public class OAContractSeal : AuditedEntity<int>
    {
        [Required]
        [MaxLength(50)]
        public string ContractName { get; set; }
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM