When using N2 with MVC you may want to use some N2 services in your controller. This is really easily achieved by simply creating a constructor for your controller with a parameter for service you require. N2 will kindly wire up the controller for you.
Here is a very simple and artificial example:
N2.Engine.IEngine engine;
public PageController(N2.Engine.IEngine engine) {
this.engine = engine;
}And here is a real example from the UserRegistrationController of the MVC templates project. This controller needs to be able to send emails to users who register and log errors.
[Controls(typeof (UserRegistration))]
public class UserRegistrationController : TemplatesControllerBase<UserRegistration>
{
private readonly IErrorHandler errorHandler;
private readonly IMailSender mailSender;
public UserRegistrationController(IMailSender mailSender, IErrorHandler errorHandler)
{
this.mailSender = mailSender;
this.errorHandler = errorHandler;
}
No comments:
Post a Comment