Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think what you are looking for is somewhat the following scenario:</p> <pre><code>public class InviteFriend { [Required] public string EmailAddress { get; set; } // More information } public interface ICommand { void Execute(); } public class InviteFriendCommand : ICommand { public InviteFriend(InviteFriend info, IUserRepository userRepo, IMailSender mailSender) { this.inviteFriend = info; this.userRepo = userRepo; this.mailSender = mailSender; } public void Execute() { var user = this.userRepo.GetUser(this.inviteFriend.EmailAddress); if (user == null) { this.userRepo.SaveInvite(this.inviteFriend.EmailAddress); } MailMessage toSend = new MailMessage(); // Obviously some logic to prepare the body, subject and other mail properties this.mailSender.Send(toSend); } } public interface ICommandFactory { ICommand CreateInviteFriendCommand(InviteFriend info); } public class CommandFactory { public CommandFactory(IResolutionRoot resolutionRoot) { this.resolutionRoot = resolutionRoot; } ICommand CreateInviteFriendCommand(InviteFriend info) { this.resolutionRoot.Get&lt;InviteFriendCommand&gt;(new ConstructorArgument("info", info)); } } public class YourController { // Somewhere var command = this.commandFactory.CreateInviteFriendCommand(info); command.Execute(); } public class YourModule : NinjectModule { override Load() { Bind&lt;IUserRepository&gt;().To&lt;UserRepo&gt;().InRequestScope(); Bind&lt;ICommandFactory&gt;().To&lt;CommandFactory&gt;().InRequestScope(); Bind&lt;InviteFriendCommand&gt;().ToSelf().InRequestScope(); } } </code></pre> <p>Forgive me when you need to tweak it a bit. I hacked it together with my out of brain compiler ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload