MVC控制器实现接口

时间:2013-02-18 23:30:38

标签: c# asp.net-mvc castle-windsor

有没有人设法在Castle Windsor的MVC 4中做以下事情?我正在观看有关六角形建筑和视频的视频后进行实验。试图更多的域驱动 - 即专注于对象之间的消息。

public class UserController : Controller, ICreatedUser
{
   public IUserCreator _creator;

   public class UserController(IUserCreator creator)
   {
      _creator = creator;
   }

   public void Create(CreateUserModel model)
   {
      _creator.Create(model);
   }

   public ViewResult Successful(User user)
   {
       return View(user);
   }

   public ViewResult Unsuccessful()
   {
      return View();
   }
}
public interface ICreatedUser
{
   ViewResult Successful(User user);
   ViewResult Unsuccessful();
}

public class UserCreator : IUserCreator
{
  private ICreatedUser _createdUser;

  public class UserCreator(ICreatedUser createdUser)  // I want the controller injected here
  {
      _createdUser = createdUser;
  }
}

我知道其中一个问题是ICreatedUser上的“ViewResult”对于UI来说太具体了 - 可能是C#的限制。

0 个答案:

没有答案