David
David

Reputation: 1841

NHibernate naming semantics

A rather trivial question but I'd like to know from anyone who uses NHibernate and the repository pattern what they name their concrete implementations.

So say you have IEmployeeRepository, would you name your concrete repositories say:

I know in the grand scheme of things it doesn't matter but I'd quite like to know if there is some kind of standard.

Cheers.

Upvotes: 0

Views: 74

Answers (3)

cbp
cbp

Reputation: 25628

I avoid adding NHibernate to the naming of my repositories, because sometimes the repositories end up accessing data without using NHibernate. What if you want to mix some legacy code that just uses ADO.NET for example? Your naming would then imply that you need a seperate class, but then you've got two seperate classes both playing the role of IEmployeeRepository.

Starting every repository with the word "NHibernate" might sound like fun now, but you'll cringe at it one day when you have hundreds of entities, all with their own carefully label "NHibernate" repository.

BTW. If you're starting a new greenfields project, you might want to research alternatives to the repository pattern. The last few year it is has started to drop out of favour.

Upvotes: 1

Leila
Leila

Reputation: 328

I don't know if exists a pattern for NHibernate, but based on conventions to name everything on code (Clean Coder), you need to put names that are significant, avoiding the use of acronyms. So NHibernateEmployeeRepository brings more significance and lets the code clear.

Upvotes: 1

devdigital
devdigital

Reputation: 34349

We call ours NHibernate***Repository, because it's probably the most descriptive. What if you have a repository for nice horses? Then it would be called NhNhRepository. Which would be confusing.

Alternatively, if you don't like the wordiness, then another option is to use namespaces, and place your NHibernate repository implementations in their own assembly (which you should probably be doing anyway).

Then, your repositories can just be called, e.g. EmployeeRepository, and sit in a CompanyName.ProductName.Data.NHibernateRepositories namespace for example.

Upvotes: 3

Related Questions