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 Answer 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
-
Thanks Ewan, By "WCF project" or service I mean the whole class with
[ServiceBehavior]
decorator. I inject 4 different service fromService 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 andService Layer
. So I started thinking.. hm.. maybe I should create more WCF[ServiceBehavior]
services (with different contracts). Hm.. interesting, Can services inService Layer
be nested?Marshall– Marshall03/16/2018 14:49:08Commented Mar 16, 2018 at 14:49 -
then you are hosting multiple services in one hosting project? split itEwan– Ewan03/16/2018 14:56:14Commented Mar 16, 2018 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– Marshall03/16/2018 21:07:48Commented Mar 16, 2018 at 21:07
Explore related questions
See similar questions with these tags.
IMapper
andDbContextFactory
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?Service Layer
.