i´m building webapi , have questions...
i created services each request, product, customer, sales, etc.. each service inject repositories tables inherits base repository like:
public productservice(iproductrepository productrepository, iproductpricerepository productpricerepository, iproductproviderrepository productproviderrepository) { }
and example saleservice requires other services like:
public salesservice(idocumentservice documentservice, icustomerservice customerservice, iproductservice productservice) { }
more or less that´s architecture of app. question need database context api configuration how proper way make without making injections redundants? :
public productservice(iproductrepository productrepository, iproductpricerepository productpricerepository, iproductproviderrepository productproviderrepository, configurationapicontextservice configurationapicontextservice) { } public salesservice(idocumentservice documentservice, icustomerservice customerservice, iproductservice productservice, configurationapicontextservice configurationapicontextservice) { }
i´m using ioc unity. that´s proper way add datacontext services? posible make new datacontext global accesible entire app?
if proper way, if later want add log4net package logging entire application, there injections service?
sorry question, started on webapi ;)
and sorry bad english too.
thanks in advance.
your constructor shouldn't have many parameters. have 4 parameters, it's fine. can use aggregate services combine services (combine if have logical or psyhical relation).
for example if customerservice , document services live together, create aggreate service them. if read refactoring aggregate services document understand more.
but far can see doing on product service.
i suggest use interface configurationapicontextservice
. that's way can test , lose coupling implemantation.
you can't loose coupling rules(interfaces) can loose coupling implemantations in depdency injection. additionally, decide implemantations on top level not in middle or bottom (inversion of control).
so sales service coupled product service rules (iproductservice
) not implemantation.
Comments
Post a Comment