So I have some general questions for you guys. As you know, I have several versions of my forum app that I’m working with, and these questions are centered around the FluentNHibernate / Castle version.
Before reading and answering these questions, you should know that in this solution I have created some base libraries that house anything I think is abstracted enough to be reused later in other apps. My solution structure looks like this:
FluentEngine.Application
FluentEngine.Domain
FluentEngine.Persistence
FluentEngine.Web
Venue.Application
Venue.Domain
Venue.Persistence
Venue.Web
- The FluentEngine.Domain library contains the following classes and interfaces: Entity, Entity<T>, ValueObject, PropertyCache, SignatureAttribute, IRepository<T> and IRepository<T, I>. The entity classes and the ValueObject classes provide base overrides for Equals, GetHash, ==, and !=. The enity classes also include the Id property so that subclasses do not need to do it. The signature attribute is used in the entity classes and is used in marking properties to be used for domain comparison.
Questions:
How necessary is this approach?
Do you use something similar yourself?
If not, do you just add the Id property yourself?
- Two of my entities are self referencing tables, meaning they maintain a list of like entities as children. Normally, I would not want a back reference to one such entities parent, nor would I care to include the parent id as a readonly property. Child entities should not care about the parent. However, my routing schema doesn’t move beyond the basic {controller}/{action}/{id} pattern. Therefore, I am not certain how to perform an action that requires knowledge of an entities parent. An example would be in building a navigation list as show below:
[HttpGet]
public ActionResult Edit(int id)
{
// get the item
Forum entity = forumRepository.SelectById(id);
// create the model
ForumEditModel model = Mapper.Map<ForumEditModel, Forum>(entity);
// view models are based on MasterViewModel
// and I need to include some navigation bits
// which are built using the entity parent ancestry.
model.NavBits(entity);
// let the base controller fill in the master view
// model base with other global properties.
PrepareMasterView(model)
return the view
return View(model);
}
So here is the problem. If the entity has no knowledge of it’s parent, how am I to reverse recurse the parent ancestry in order to build these bits?
Questions:
Is it OK to have a protected set property, exposing the entity parent id? I.E.
public virtual int ParentId { get; protected set; }