내 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 속성에 setter를 추가하여 쓰기 가능하도록 할 수 있습니까? 생성자에서 매개 변수로 ICustomService를 추가 하시겠습니까? –
[ASP.Net Core (MVC 6) - Action Filter에 서비스 삽입]의 가능한 복제본] (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) –