Quantcast
Channel: URF - Unit of Work & (extensible/generic) Repositories Framework
Viewing all articles
Browse latest Browse all 1539

New Post: Circular Dependency Error

$
0
0
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.

Viewing all articles
Browse latest Browse all 1539

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>