Base solution for your next web application
Open Closed

Castle.MicroKernel.Handlers.HandlerException! #4426


User avatar
0
zokho created

I have got the following classes/interface:

public interface IJobManager
    {
        Task<Job> Publish(Job job);
    }
public class JobManager: IJobManager
    {
        private readonly IUnitOfWorkManager _unitOfWorkManager;
        private readonly ILocalizationManager _localizationManager;
        private readonly IRepository<Job, long> _jobRepository;

        public JobManager(
            IUnitOfWorkManager unitOfWorkManager,
            ILocalizationManager localizationManager,
            IRepository<Job, long> jobRepository
            )
        {
            _unitOfWorkManager = unitOfWorkManager;
            _localizationManager = localizationManager;
            _jobRepository = jobRepository;
        }

        public async Task<Job> Publish(Job job) {
            //ToDo: Check the available credit
            job.PublishStart = DateTime.Now;

            return job;
        }
    }
public class JobAppService : AgbizCareersDemoAppServiceBase, IJobAppService
    {
        private readonly IRepository<Job, long> _jobRepository;
        private readonly IJobManager _jobManager;

        public JobAppService(
            IRepository<Job, long> jobRepository,
            IJobManager jobManager)
        {
            _jobRepository = jobRepository;
            _jobManager = jobManager;
        }
[AbpAuthorize(AppPermissions.Pages_Job_Manage)]
        public async Task<JobDto> PublishJob(EntityDto<long> input)
        {
            var job = await _jobRepository.GetOwnAsync(input.Id);

            job = await _jobManager.Publish(job);

            return ObjectMapper.Map<JobDto>(job);
        }

}

I am getting the following error in the log file:

'AgbizCareersDemo.Jobs.JobAppService' is waiting for the following dependencies:

  • Service 'AgbizCareersDemo.Jobs.IJobManager' which was not registered.

Castle.MicroKernel.Handlers.HandlerException: Can't create component 'AgbizCareersDemo.Jobs.JobAppService' as it has dependencies to be satisfied.

I have already created a service class in my other projects and I didn't have to resolve any dependency myself. Has anything been changed in that regard in the recent update?


3 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    You need to inherit ITransientDependency:

    public class JobManager: IJobManager, ITransientDependency
    
  • User Avatar
    0
    zokho created

    Well done! Thanks for that Aaron, but would you please tell me why I could do it without that inheritance? And why the UserLinkManager does not inherit the ITransientDependency? Does the documentation have any reference to the ITransientDependency?

    Cheers,

  • User Avatar
    0
    aaron created
    Support Team

    why the UserLinkManager does not inherit the ITransientDependency?

    UserLinkManager inherits DomainService, so it's covered by Conventional Registrations.

    Does the documentation have any reference to the ITransientDependency?

    Yes, the Dependency Injection documentation mentions that in the Helper Interfaces section.