Hi

I have been working with NH for some years now and have seen a pattern 
emerging in my code that I'd like to see if there is a better way of 
handling.

Most of my "service/handler" classes do stuff like this:

public class CreateCustomerCommandHandler: IHandleCommand<
CreateCustomerCommand>{

  private ISession _session;

  public CreateCustomerCommandHandler(ISession session){
    _session = session;
  }

  public void Handle(CreateCustomerCommand cmd){
    var customerType = _session.Get<CustomerType>(cmd.customerTypeId);
    var customerSex = _session.Get<CustomerSex>(cmd.customerSexId);
    var client = _session.Get<Client>(cmd.ClientId);
    //More entity loads here
    
    if(customerType == null)
      throw new NotFoundException($"CustomerType not found with id of 
{cmd.customerTypeId}");

    //More checks for null here
  }

}

What I would like to do is to check an Entity Id Cache of some sort before 
the code reaches my "Handler" classes. That way I know whether the entity 
is in the DB before I run my handler code.

Think of it like Validation for entities existing.

I could then implement a CommandInterceptor which does the Id validation 
before passing off to the CommandHandler.

public class CreateCustomerCommand: ICommand{
  [EntityCache(typeof(CustomerType))]
  public customerTypeId {get;set;}
  //etc...
}



I know the second level cache exists and I can cache entities in that which 
does kinda give me what I want (with the benefit that when I do the load in 
the Handler no need to go to the DB).

I just wondered if there was another pattern or feature of NH I was missing 
in order to achieve what I am trying to do?

Any thoughts would be greatly appreciated.

Thanks, Mark

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to