Our project uses a constructor-based Injection Dependency Injection (we use Unity as our container), and we have a number of designers who have acquired a large number of parameters.
For example:
public FooRequestService(
ITransactionDataBuilder transactionDataBuilder,
IMapper<SaveFooRequest, FooRequestMessage> saveFooRequestToFooRequestMapper,
IFooRequestedThingRepository fooRequestedThingRepository,
IFooRequestedThingBuilder fooRequestedThingBuilder,
IMapper<IEnumerable<FooRequestedThing>, IEnumerable<FoundFooRequestedThing>> fooRequestedThingsToFoundFooRequestedThingsMapper,
IAutomatedFooWcfService automatedFooService,
IFooArrivalMessageProvider fooArrivalMessageProvider,
ISeatCancellation cancellation,
IPostSalesService postSalesService,
ITransactionEnquiryService transactionService,
IMapper<IEnumerable<FooRequestedThing>, List<ThingArrivedForFoo>> thingArrivalRequestDocumentMapper,
IMapper<SaveFooRejected, FooRejectedMessage> saveFooRejectedToFooRejectedMapper,
IPartialFooConfiguration partialFooConfiguration,
ICurrentDateTimeProvider currentDateTimeProvider,
IMapper<FooRequestMessage, List<FooRequested>> tracsFooRequestMapper,
IThreeWayMerger<Transaction, TransactionService.Contract.Transaction, NotifyFooRequestedRequest, SaveFooRequest> saveFooRequestMerger,
KioskWebServiceSoap kioskServiceGateway)
{
// code here to set injected values to member variables
}
This class contains about 370 lines of code and represents the main part of the system, therefore, a large number of dependencies.
- From the DI point of view, are there usually so many parameters passed to the constructor?
- The general approach concerns me in terms of encapsulation and review. All dependencies can be used from anywhere inside the class, even if they should (strictly speaking) be used only, for example, from one method