我使用Castle DI繼承了一個項目。我將WCF添加到解決方案中,並需要使用解決方案中的一些功能。這個類有以下,我假設是注入。DI城堡WCF構造函數我如何
private readonly IOrderRepository _orderRepository;
private readonly IEshopOrderRepository _eShopOrderRepository;
private readonly IUserRepository _userRepository;
private readonly IListRepository _listRepository;
private readonly INHibernateRepositoryWithTypedId<ProductVariant, string> _productVariantRepository;
private readonly IMapper<GiftCardPayment, string, GiftCardPaymentDto> _giftCardDtoMapper;
private readonly IMapper<AbstractOrder, OrderDto> _orderDtoMapper;
private readonly IMapper<AbstractOrder, RecurringOrder> _recurringOrder;
private readonly IMapper<Address, CreditCardPaymentDto> _creditCardDtoMapper;
public delegate OrderDto ShipmentProcessing(OrderDto order, bool isRecap);
public OrderManagementService(IOrderRepository orderRepository, IUserRepository userRepository, IListRepository listRepository,
IEshopOrderRepository eShopOrderRepository,
INHibernateRepositoryWithTypedId<ProductVariant, string> productVariantRepository,
IMapper<GiftCardPayment, string, GiftCardPaymentDto> giftCardDtoMapper,
IMapper<AbstractOrder, OrderDto> orderDtoMapper,
IMapper<AbstractOrder, RecurringOrder> recurringOrder,
IMapper<Address, CreditCardPaymentDto> creditCardDtoMapper)
{
_orderRepository = orderRepository;
_eShopOrderRepository = eShopOrderRepository;
_userRepository = userRepository;
_listRepository = listRepository;
_productVariantRepository = productVariantRepository;
_giftCardDtoMapper = giftCardDtoMapper;
_orderDtoMapper = orderDtoMapper;
_recurringOrder = recurringOrder;
_creditCardDtoMapper = creditCardDtoMapper;
}
所有這些工作。我的問題是如何在WCF服務類中實現這種模式。我無法將參數添加到構造函數中,因爲客戶端不會提供它們。
我能夠在WCF中使用DI,以便部分工作。
感謝
這是一個很大你有沒有依賴性。您可能想要重構該類。看看[這裏](http://blog.ploeh.dk/2010/01/20/RebuttalConstructorOverinjectionAntipattern.aspx)。 – Steven