1

I have a controller named HomeController

public class HomeController : ApiController
{       
    [System.Web.Http.HttpGet]
    public string Index()
    {
       //Some logic
    }
}

And an Attribute class named Logging

public class Logging : ActionFilterAttribute
{
    private readonly IMyInterface myInterface;
    public LogResponse(myInterface value)
    {
        //Add Validation
        myInterface = value;
    }

    public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
    {
        // some logic
    }
}

I want to use the binding but I dont know how can I use Ninject here.

In my Ninject file, I tried:

private static void RegisterServices(IKernel kernel)
{
    kernel.BindHttpFilter<LogResponse>(FilterScope.Controller)
        .WithConstructorArgument("Report", ???) // ?? says some object , but what value ?
}

Could you please help me with Ninject function

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
devam demo
  • 63
  • 1
  • 6

2 Answers2

0

You might need to create an additional FilterAttribute, and use that in your binding.

See https://stackoverflow.com/a/6194159/146205 for a more detailed example.

Community
  • 1
  • 1
Jensen
  • 3,498
  • 2
  • 26
  • 43
0

1) The constructor name seems different than the class name, maybe a typing error 2) Not familiar with NInject, but I assume you have a type registration for IMyInterface; in that case use the container to obtain an instance of that and pass it to the WithConstructorArgument method (assuming it does what it's name says). Careful with the param name, it should be value (and there is another error right there, in the constructor signature, it should be IMyInterface value). Hope it applies.

Silviu Preda
  • 628
  • 1
  • 10
  • 31