I am creating an ASP.NET MVC application that uses the DDD (Domain Driven Design) approach with database access handled by NHibernate. I have a domain model class (Administrator) in which I want to inject dependency through an IOC container such as Castle Windsor, something like this:
public class Administrator { public virtual int Id { get; set; }
Basically, I want to use the IHashingService method for the SetPassword method without directly calling the IOC container (since this is supposedly an IOC anti-pattern). But I'm not sure how to do this. The My Admin object is either created through new Administrator(); , or loaded via NHibernate, so how can I add IHashingService to the Administrator class?
Secondly, am I going to do it right? I was hoping to avoid having my code base litter ...
currentAdmin.Password = HashUtils.Hash(password, Algorithm.Sha512);
... and instead, the domain model itself should take care of hashing and carefully encapsulate it. I can provide for another developer mistakenly choosing the wrong algorithm and having some passwords like Sha512, and some MD5, some with one salt, and some with another salt, etc. Etc. Instead, if the developers write ...
currentAdmin.SetPassword(password);
... then it will hide these details and take care of the problems listed above, right?
asp.net-mvc inversion-of-control ioc-container nhibernate castle-windsor
Sunday ironfoot
source share