'How can I both dependency injection and send value inside the attribute in .net core?
I want to decrpyt the request and encrypt the result by attribute. For this, I wrote the CheckFilter attribute below. But I need to do dependency injection to use IHashService service in it. I also want to send a value with attribute as it is used in the Get method. But I don't know how to do this.
public class CheckFilter : Attribute, IResourceFilter
{
private readonly IHashService _hashService;
public CheckFilter(IHashService hashService)
{
_hashService = hashService;
}
public void OnResourceExecuting(ResourceExecutingContext context)
{
//Decrypt
}
public void OnResourceExecuted(ResourceExecutedContext context)
{
//Encrypt
}
}
[HttpGet]
[CheckFilter("test")]
public string Get(string request)
{
return "hello";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
