patterncsharpMinor
What standard should I use for the naming of my MVC controller services?
Viewed 0 times
themvcwhatnamingstandardcontrollerservicesforshoulduse
Problem
I have the following:
Note that it's completely mixed up with different naming standards.
Is there anything recommended for the naming of services that are used by my controller?
public class ContentsController : BaseController {
private IContentService _content;
private IPageService pageService;
private IReferenceService _reference;
private ISequenceService seqService;
public ContentsController(
IContentService contentService,
IPageService pageService,
IReferenceService referenceService,
ISequenceService sequenceService) {
this._content = contentService;
this.pageService = pageService;
this._reference = referenceService;
this.seqService = sequenceService;
}Note that it's completely mixed up with different naming standards.
Is there anything recommended for the naming of services that are used by my controller?
Solution
I don't think it matters as long as you are consistent. I personally prefer: _{servicename}Service format. ex. _referenceService
public class ContentsController : BaseController {
private IContentService _contentService;
private IPageService _pageService;
private IReferenceService _referenceService;
private ISequenceService _seqService;
public ContentsController(
IContentService contentService,
IPageService pageService,
IReferenceService referenceService,
ISequenceService sequenceService) {
this._contentService = contentService;
this._pageService = pageService;
this._referenceService = referenceService;
this._seqService = sequenceService;
}Code Snippets
public class ContentsController : BaseController {
private IContentService _contentService;
private IPageService _pageService;
private IReferenceService _referenceService;
private ISequenceService _seqService;
public ContentsController(
IContentService contentService,
IPageService pageService,
IReferenceService referenceService,
ISequenceService sequenceService) {
this._contentService = contentService;
this._pageService = pageService;
this._referenceService = referenceService;
this._seqService = sequenceService;
}Context
StackExchange Code Review Q#15614, answer score: 5
Revisions (0)
No revisions yet.