以下のようなモデルバインダーがあります
public PartyRoleModelBinder(IPartyRoleFactory prFactory)
{
PrFactory = prFactory;
PRepo = pRepo;
PrtRepo = prtRepo;
}
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
{
//doing some work here
}
private IPartyRoleFactory PrFactory { get; set; }
private IPartyRepository PRepo { get; set; }
private IPartyRoleTypeRepository PrtRepo { get; set; }
以下のように global.asax.cs に登録しています。
ModelBinders.Binders.Add(typeof(PartyRole), new PartyRoleModelBinder(DependencyResolver.Current.GetService<IPartyRoleFactory>()));
ここまでは順調です。今私の問題は、コンストラクターへの依存関係がさらに必要になることです。たとえば、次のようになります。
public PartyRoleModelBinder(IPartyRoleFactory prFactory, IPartyRoleTypeRepository prtRepo, IPartyRepository pRepo)
{
PrFactory = prFactory;
PRepo = pRepo;
PrtRepo = prtRepo;
}
しかし、これをglobal.asax.csに登録する方法は確かです
以下のように使用すると
ModelBinders.Binders.Add(typeof(PartyRole), new PartyRoleModelBinder(DependencyResolver.Current.GetService<IPartyRoleFactory>()));
それはスローします: エラー 25 'PartyWeb.ModelBinders.PartyRoleModelBinder' には 1 つの引数を取るコンストラクターが含まれていません C:\d2\Apps\d2admin\Global.asax.cs 35 57 d2admin
または
ModelBinders.Binders.Add(typeof(PartyRole), new PartyRoleModelBinder(DependencyResolver.Current.GetService<IPartyRoleFactory, IPartyRepository, IPartyRoleTypeRepository>()));
コンパイル エラー: エラー 25 非ジェネリック メソッド 'System.Web.Mvc.IDependencyResolver.GetService(System.Type)' は型引数 C:\d2\Apps\d2admin\Global.asax.cs で使用できません 35 109 d2admin
誰かがそれを解決する方法を教えてもらえますか?