Circular Dependency Error

Oct 29, 2014 at 9:49 AM
Edited Oct 29, 2014 at 10:04 AM
When attempting to inject Services in other Services, it's causing Circular Dependencies and Stackoverflow exception.

As I need to call a method in another service which has some business logic.

Is this the right approach?
public partial class SalesOrderBaseService : Service<SalesOrder>, ISalesOrderService
        public readonly IRepositoryAsync<SalesOrder> _repository;
        public readonly ICustomerService _customerService;
        public readonly IDeliveryOrderService _deliveryOrderService;
        public readonly IInvoiceService _invoiceService;
        public readonly IPackingListService _packingListService;

        public SalesOrderBaseService(IRepositoryAsync<SalesOrder> repository,
            ICustomerService customerService,
            IDeliveryOrderService deliveryOrderService,
            IInvoiceService invoiceService,
            IPackingListService packingListService)
            : base(repository)
            _repository = repository;
            _customerService = customerService;
            _deliveryOrderService = deliveryOrderService;
            _invoiceService = invoiceService;
            _packingListService = packingListService;
public class DeliveryOrderBaseService : Service<DeliveryOrder>, IDeliveryOrderService
        private readonly IRepositoryAsync<DeliveryOrder> _repository;
        private readonly ISalesOrderService _salesService;

        public DeliveryOrderBaseService(IRepositoryAsync<SalesOrder> repository, 
            ISalesOrderService salesService)
            : base(repository)
            _repository = repository;
            _salesService= salesService;
IDeliveryOrderService will be injected, which will resolve the ISalesOrderService, which will then again resolve the IDeliveryOrderService, and so on.
Dec 20, 2014 at 1:45 AM
Without further context, we're not able to gather the real problem. This could be related to the DI/IoC framework configuration you have and you or the framework have configured or handle the lifecycle of these instances in our container. Again, that's just a wild guess at this point.
Marked as answer by lelong37 on 12/19/2014 at 5:45 PM