有没有人设法在 MVC 4 中使用 Castle Windsor 做到以下几点?在观看有关六边形架构的视频并尝试更多地驱动领域后,我目前正在尝试 - 即专注于对象之间的消息。
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# 的限制。