3
我使用ASP .NET MVC和Ninject。我需要條件綁定參數名稱。我怎樣才能做到這一點?Ninject按參數名稱綁定
private readonly ITemplateProvider _msgTemplate;
private readonly ITemplateProvider _mailTemplate;
public OrderLineManager(ITemplateProvider msgTemplate,ITemplateProvider mailTemplate)
{
_msgTemplate = msgTemplate;
_mailTemplate = mailTemplate;
}
//ninject kernel ,
//i need for msgTample MessageTemplateProvider
//i need for mailTemplate MailTemplateProvider
_kernel.Bind<ITemplateProvider>()
.To<MessageTemplateProvider>()
.When(request => request.Target.Member.Name.Equals("msgTemplate"));
_kernel.Bind<ITemplateProvider>()
.To<MailTemplateProvider>()
.When(request => request.Target.Member.Name.Equals("mailTemplate"));