私は自分のASP.NET CORE
アプリケーションではどこでも、コンストラクタベースの依存性注入を使用して、私はまた私のアクションフィルタで依存関係を解決する必要があります:私はICustomServiceを置く場合ASP.NET COREで依存フィルタを使用したアクションフィルタの使用方法
[MyAttribute(Limit = 10)]
public IActionResult()
{
...
:
その後public class MyAttribute : ActionFilterAttribute
{
public int Limit { get; set; } // some custom parameters passed from Action
private ICustomService CustomService { get; } // this must be resolved
public MyAttribute()
{
}
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
// my code
...
await next();
}
}
コントローラに私のプロジェクトをコンパイルできません。だから、アクションフィルタでインターフェースインスタンスを取得するために私はどのようにsupossedしますか?
プロパティCustomServiceにセッターを追加して書き込み可能にすることはできますか?コンストラクタのパラメータとしてICustomServiceを追加しますか? –
[ASP.Net Core(MVC 6) - アクションフィルタにサービスを注入]の可能な複製](http://stackoverflow.com/questions/36109052/asp-net-core-mvc-6-inject-service-into-action -filter) – gilmishal
[asp.net?]のアクションフィルタにパラメータを追加するにはどうすればいいですか?(http://stackoverflow.com/questions/39181390/how-do-i-add-a-parameter-to -an-action-filter-in-asp-net) –