How to get the object of ITelemety
object in an ASP.NET Core custom ActionFilterAttribute
using dependency injection?
Platform - .Net Core
What is required : ITelemetry object
Sample Code for reference
public class CustomActionFilterAttribute : ActionFilterAttribute
{
private readonly ITelemetry telemetry;
public CustomActionFilterAttribute(ITelemetry telemetry)
{
this.telemetry= telemetry;
}
}
I need to resolve ITelemetry
object to add few Global Properties in the request context so that those can be logged in Request log. With above sample code, an exception is thrown when ITelemetry
object is not being resolved by DI.
The CustomActionFilterAttribute
is injected as shown below in startup.
services.AddMvc(options =>
{
options.Filters.Add<CustomActionFilterAttribute>();
});