Good naming for domain services layer [closed]
Asked Answered
A

4

9

Abstract

Which name is better?

  • Domain.PersonService
  • DomainServices.PersonService
  • DomainServices.PersonDomainService (consider some longer names like PersonDomainServiceModelDecorator)

or something else?

Situation

We have a framework in which there are some base classes for each layer. Ex. Repository, Domain Services, UI, etc.

Each logical layer has a name which is used as its namespace:

  • "Data" for data layer that contains repositories; Ex. Fx.Data.DbContextRepository
  • "Services" for domain (not web) service layer; Ex. Fx.Services.CrudService
  • "Web.UI" for Web UI layer; Ex. Fx.Web.UI.Controllers.CrudController

We also follow the same rule for end-projects whith some extra layers:

  • "Data" Ex. Project.Data.PersonRepository
  • "Services" Ex. Project.Services.PersonService
  • "Web.UI" Ex. Project.Web.UI.Controllers.PersonController
  • "Entities" for code-first entities; Ex. Entities.Person
  • "Models" for object models; Ex. Models.Person.Criteria, Models.Person.PersonDeleteModel

My focus is on "Domain Service" layer but any ideas about other layers are also welcomed.

We've finally come to the conclusion that "Services" is not a suitable name for "Domain Services" as it may cause ambiguity between a "Web Service" or "Domain Service" layer.

Now we are changing the "Services" namespace to "Domain" or "DomainServices". But we have another problem. We put a "Service" suffix for every domain service class (Ex. PersonService). Now it seems ugly to have "DomainService" suffix (Ex. DomainServices.PersonDomainServer or DomainServices.DomainPersonService).

So it can be prettier to use "Domain" as namespace while class names show that they're services under domain namespace (Ex. Domain.PersonService).

Alexandretta answered 20/7, 2013 at 8:3 Comment(0)
M
6

I would go for two simple ideas:

  1. try to define full names (namespace + type name) without redundancy (the same name portion - Domain, Person, Service, Model, Controller, ... - should not appear twice) whenever possible

  2. get inspiration from the .NET framework itself. There are more than 40000 classes in there! Open all the assemblies in a tool such as .NET Reflector or ILSpy and study it carefully.

I would come up with something like this:

Domain
 + Person
 + PersonService // Domain service
Domain.Data
 + PersonRepository
Domain.ServiceModel // WCF, etc. I chose the same namespace as .NET Framework
 + PersonService // Service implementation, this is really a service so "service" redundancy seems unavoidable here
Domain.Web.UI
 + PersonController

Ok, it has the obvious inconvenient that the same type name appears multiple times in the hierarchy. Well, but that's why namespaces (and namespace aliases) exists also. I think it's not such a big deal.

Mattern answered 28/7, 2013 at 6:48 Comment(0)
C
3

Do you see any difference between Domain and DomainServices in your project? If you want to keep services and other domain entities in separate namespaces I believe you will need to move PersonService to DomainServices namespace.

Most of the time we do not look into namespace, we only mention classes that's why I think it is fine to have DomainServices namespace. At the same point of time if you have single domain across the application and do not have plan to separate it, I think it will be better to call it Domain.PersonService

Regarding the word 'Doman' in the class names, I really don't like this because it adds complexity to the name. You should try to build your application that way to be sure if you are opening PersonService you should be 100% sure it is domain service. You know that when you are opening PersonRepository, it is Data layer, the same for domain.

Coelacanth answered 23/7, 2013 at 7:23 Comment(0)
L
2

I would do this in either of these two ways:

1) Why not have subnamespaces for Services:

  • Services.Web for web servies
  • Services.Domain for domain servces

On another note, I would remove Web from Web.UI (provided that you do only have a web based UI).

2) If web services are actually living in the web layer they could be in Web.Services namespace in that case Web.UI is also acceptable. Domain Services would live simply in Services namespace.

Ludivinaludlew answered 27/7, 2013 at 11:32 Comment(0)
W
1

My suggestion would be to put it as <Company>.<Component>.<SubComponent>.<Module>.DLL**. Microsoft recommends something similiar on this link http://msdn.microsoft.com/en-us/library/vstudio/ms229048(v=vs.100).aspx and an example will be **Microsoft.Practices.EnterpriseLibrary.Security.Dll

Hence, you might want to go with Company.Domain.PersonService

Weldonwelfare answered 29/7, 2013 at 17:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.