1

I want to expose my business logic via WCF service in the intranet environment. I have N-tier architecture, pretty simple:

Database -> .Data (DAL) -> .Business (Service Layer) -> WCF

So, far I have 4 services in Service Layer, but only one WCF service. I here comes the problem. My WCF service uses all 4 services. I'm using Dependency Injection, so technically I should add those 4 services into WCF constructor. I already has parameter for IMapper, ILogger and DbContextFactory.

I was thinking of creating a ServiceFactory and passing it to the WCF service. So then, WCF Service can create whatever service it needs.

But I'm not sure if this is an antipattern or not? What do you suggest?

  • 1
    What problem are you trying to solve? If your proposed change doesn't solve a problem, you don't need it. – Robert Harvey Mar 14 '18 at 19:46
  • @RobertHarvey The problem I have is that it's getting smelly. I got rid of IMapper and DbContextFactory since they are injected into Services themselves and are not needed in WCF service, but it's still 5 parameters. So I have an idea, to create a factory for Services. I'm not sure if this is a good practice though - it sounds like Service Locator anti-pattern, doesn't it? – Marshall Mar 14 '18 at 20:04
  • It sounds like you haven't done a cost-benefit analysis. – Robert Harvey Mar 14 '18 at 20:18
  • @RobertHarvey what does it mean? Do you have any advice? My second idea, was to create many WCF services , one per service from the Service Layer. – Marshall Mar 14 '18 at 20:22
  • Forget about code smell for a moment. What's the simplest thing that will work? – Robert Harvey Mar 14 '18 at 20:36
1

You should avoid business logic in the WCF project.

If your WCF project uses more than one Service Layer project then it must(?) have some business logic in it.

Either: Make a new WCF 'hosting layer' project for each Service Layer project

Or: Make a new Service Layer project which encapsulates the others and the business logic which links them

| improve this answer | |
  • Thanks Ewan, By "WCF project" or service I mean the whole class with [ServiceBehavior] decorator. I inject 4 different service from Service Layer (btw. I hate that naming, it should be called Logic/Business layer, so it's not confused with web services). Anyway, it doesn't mean that there is business logic. There's none. I use one service per WCF method. WCF is just a proxy between the client and Service Layer. So I started thinking.. hm.. maybe I should create more WCF [ServiceBehavior] services (with different contracts). Hm.. interesting, Can services in Service Layer be nested? – Marshall Mar 16 '18 at 14:49
  • then you are hosting multiple services in one hosting project? split it – Ewan Mar 16 '18 at 14:56
  • Thanks, I think I'm gonna refactor at some point. I'm not sure yet how. When you have a Car and a bunch of methods like "GetCarById", "GetCarOwner", "GetCarsOnSale", "GetAllCars"... where should methods like "GetAllCarTypes" or "GetCarBrands" go? It's not part of the Car. Types are like "Cabro, Sedan... etc" Is it a part of the Car aggregate root? – Marshall Mar 16 '18 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.