Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to solve Can't create component as it has dependencies ? #3955


User avatar
0
manojreddy created

How to solve Can't create component as it has dependencies to be satisfied in ASP.NET Boilerplate?

Getting error while running test. How to solve?

public class TestAppService : TestAppServiceBase, ITestAppService
    {
        private readonly ITestRepository _testRepository;
        public TestAppService(ITestRepository testRepository)
        {
            _testRepository = testRepository;
        }

public class TestAppService_Test : TestAppServiceTestBase
    {
        private readonly ITestAppService _testAppService;

    public TestAppService_Test()
    {
        _testAppService = Resolve<ITestAppService>();
    }


Test Name:  

ABC.XYZ.Tests.PQR.TestAppService_Test.Should_Create_Test_With_Valid_Arguments
Test FullName:  ABC.XYZ.Tests.PQR.TestAppService_Test.Should_Create_Test_With_Valid_Arguments (20f54c54e5d9f077f4cb38b988ecb8e63e07d190)
Test Source:    C:\Users\viveknuna\source\repos\XYZ\aspnet-core\test\ABC.XYZ.Tests\PQR\TestAppService_test.cs : line 25
Test Outcome:   Failed
Test Duration:  0:00:00.001

Result StackTrace:  
at Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency()
   at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
   at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
   at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy)
   at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy)
   at Castle.Windsor.WindsorContainer.Resolve[T]()
   at ABC.XYZ.Tests.PQR.TestAppServiceTestBase..ctor() in C:\Users\viveknuna\source\repos\XYZ\aspnet-core\test\ABC.XYZ.Tests\PQR\TestAppServiceTestBase.cs:line 14
   at ABC.XYZ.Tests.PQR.TestAppService_Test..ctor() in C:\Users\viveknuna\source\repos\XYZ\aspnet-core\test\ABC.XYZ.Tests\PQR\TestAppService_test.cs:line 17
Result Message: 
Castle.MicroKernel.Handlers.HandlerException : Can't create component 'ABC.XYZ.Business.Services.PQR.TestAppService' as it has dependencies to be satisfied.

'ABC.XYZ.Business.Services.PQR.TestAppService' is waiting for the following dependencies:
- Service 'ABC.XYZ.Business.Repositories.Interfaces.ITestRepository' which was not registered.

6 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ManojReddy ,

    Can you share your ITestRepository and it's implementation ? You can also check it according to this document <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Repositories#custom-repository-interface">https://aspnetboilerplate.com/Pages/Doc ... -interface</a> and see if something is missing.

  • User Avatar
    0
    manojreddy created

    Please find the code below.

    public interface ITestRepository : IRepository<Test, int>
        {
            PagedResultDto<FetchTest> GetSearchTest(FetchTestInput searchInput);
    
            Task<int> CreateTest(TestDetailsDTO input);
    
            Task UpdateTest(TestDetailsDTO input);
    
            TestDetailsDTO GetTestDetailsforEdit(EntityDto input);
    
            Task DeleteTest(EntityDto input);
    
            ListResultDto<FetchTest> GetTestList(string input);
    
        }
    
    public class TestRepository : TestRepositoryBase<Test, int>, ITestRepository
        {
            private readonly IActiveTransactionProvider _transactionProvider;
            public TestRepository(IDbContextProvider<TestDbContext> dbContextProvider)
                : base(dbContextProvider)
            {
            }
    
            public TestRepository(IDbContextProvider<TestDbContext> dbContextProvider,
                IActiveTransactionProvider transactionProvider, IObjectMapper objectMapper)
            : base(dbContextProvider)
            {
                _transactionProvider = transactionProvider;
                ObjectMapper = objectMapper;
            }
    
            public async Task<int> CreateTest(TestDetailsDTO input)
            {
    
                int TestId = await InsertAndGetIdAsync(ObjectMapper.Map<Test>(input));
    
                return TestId;
    
            }
    
            public async Task DeleteTest(EntityDto input)
            {
                await DeleteAsync(input.Id);
            }
    
            public PagedResultDto<FetchTest> GetSearchTest(FetchTestInput searchInput)
            {
                var _Tests = GetAll()
                    .Where(f => (!string.IsNullOrWhiteSpace(searchInput.TestCode) ? f.TestCode.Contains(searchInput.TestCode) : true) &&
                                (!string.IsNullOrWhiteSpace(searchInput.TestDesc) ? f.TestDesc.Contains(searchInput.TestDesc) : true));
    
                var _result = (from details in _Tests
                               select new FetchTest
                               {
                                   Id = details.Id,
                                   TestCode = details.TestCode,
                                   TestDesc = details.TestDesc,
                                   TestName = details.TestName,
                                   AbcCode = details.AbcCode
                               });
    
                var TestCount = _result.Count();
                var Tests = ObjectMapper.Map<List<FetchTest>>(_result
                .OrderBy(searchInput.Sorting)
                .PageBy(searchInput)
                .ToList());
    
                return new PagedResultDto<FetchTest>(
                     TestCount,
                     Tests
                    );
            }
    
            public TestDetailsDTO GetTestDetailsforEdit(EntityDto input)
            {
                var result = (from Test in GetAll()
                              where ((Test.Id == input.Id))
    
                              select new TestDetailsDTO
                              {
                                  TestCode = Test.TestCode,
                                  TestName = Test.TestName,
                                  TestDesc = Test.TestDesc,
                                  AbcCode = Test.AbcCode
                              });
    
                int count = result.Count();
    
                return ObjectMapper.Map<TestDetailsDTO>(result.FirstOrDefault());
            }
    
            public ListResultDto<FetchTest> GetTestList(string input)
            {
                var Tests = GetAll()
                                 .Where(a => (a.Id.ToString().Equals(input) || a.TestCode.Contains(input) || a.TestDesc.Contains(input)));
    
                return new ListResultDto<FetchTest>(ObjectMapper.Map<List<FetchTest>>(Tests));
            }
    
            public async Task UpdateTest(TestDetailsDTO input)
            {
                var classobj = ObjectMapper.Map<Test>(input);
                await UpdateAsync(classobj);
            }
        }
    
  • User Avatar
    0
    manojreddy created

    @ismcagdas

    Any update?

  • User Avatar
    0
    aaron created
    Support Team
  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks a lot @aaron :)

  • User Avatar
    0
    manojreddy created

    Thanks a lot @aaron