Last post Jul 22, 2010 07:19 AM by avi_bubun
Jul 21, 2010 12:13 PM|jgd12345|LINK
Hi, i'm just starting with asp.net mvc and specifically the repository pattern. I've read as much as i can but there doesn't appear to be a great article on dependency injection (ioc) as lots of people are doing it different. I found one article
http://weblogs.asp.net/cibrax/archive/2008/08/21/dependency-injection-made-easy-for-the-asp-net-mvc.aspx and it looks simple for setting up my data context (IDataContext) against a controller. However i have my own custom DataAnnotation attribute which
makes sure that a person's name is unique:
public class UniqueUserNameAttribute : ValidationAttribute
public override bool IsValid(object value)
string str = (string)value;
using (IDataContext context = new LinqToSqlDataContext())
return context.Repository<User>().Find(u => u.UserName == str).Count() == 0;
As you can see there's a hard coded dependency on my linq to sql data context. This means i can't test but i also can't see what else i can do.
I'd really appreciate it if someone could point me in the right direction and recommend the best dependency injection library to use (such as StructureMap, Unity, Autofac...).
Jul 22, 2010 07:19 AM|avi_bubun|LINK
Use StructureMap. It is the best.