Use interface between model and view in ASP.NET MVC
- by Icerman
Hi,
I am using asp.net MVC 2 to develop a site. IUser is used to be the interface between model and view for better separation of concern. However, things turn to a little messy here. In the controller that handles user sign on: I have the following:
IUserBll userBll = new UserBll();
IUser newUser = new User();
newUser.Username = answers[0].ToString();
newUser.Email = answers[1].ToString();
userBll.AddUser(newUser);
The User class is defined in web project as a concrete class implementing IUser. There is a similar class in DAL implementing the same interface and used to persist data. However, when the userBll.AddUser is called, the newUser of type User can't be casted to the DAL User class even though both Users class implementing the interface (InvalidCastException).
Using conversion operators maybe an option, but it will make the dependency between DAL and web which is against the initial goal of using interface.
Any suggestions?