Using Ninject Intercept Attributes with Custom Controllers
I've been trying to work this out but think I'm missing something. I'm trying to get Ninject Intercept Attributes working in a custom RenderMvcController but for some reason my Interceptor class is not firing (everything builds as it should). I've applied the required Attribute to the relevant method I'm trying to intercept and also made the method virtual but no luck.
Has anyone had any experience using Ninject Interceptors before? (within Umbraco).
Here's my action ('query' being resolved by Ninject using constructor injection, got that working at least!)
public ActionResult LandingMvc()
{
var vm = query.Get();
return CurrentTemplate(vm);
}
And here's the query class which has the Interceptor attribute on its Get() method
public class LandingPageViewModelQuery : ILandingPageViewModelQuery
{
private ISiteRepository propertyRepo;
public LandingPageViewModelQuery(ISiteRepository pr)
{
propertyRepo = pr;
}
[SiteChrome]
public virtual ILandingPageViewModel Get()
{
var vm = new LandingPageViewModel();
return vm;
}
}
Finally here's the Intercept Attribute which I would have expected to have fired.
Do you need to add anything in the AppStart? So when using ninject you have to create and register module in appstart here is what my app start looks like for an mvc project i have where i use ninject may be something similar is needed to register intercept attributes? Just a theory btw :-}
Thanks Ismail, turned out I needed an extra reference to Ninject.Extensions.Interception.DynamicProxy, once that was added the interceptor attributes started working!
Using Ninject Intercept Attributes with Custom Controllers
I've been trying to work this out but think I'm missing something. I'm trying to get Ninject Intercept Attributes working in a custom RenderMvcController but for some reason my Interceptor class is not firing (everything builds as it should). I've applied the required Attribute to the relevant method I'm trying to intercept and also made the method virtual but no luck.
Has anyone had any experience using Ninject Interceptors before? (within Umbraco).
Here's my action ('query' being resolved by Ninject using constructor injection, got that working at least!)
public ActionResult LandingMvc()
{
var vm = query.Get();
return CurrentTemplate(vm);
}
And here's the query class which has the Interceptor attribute on its Get() method
public class LandingPageViewModelQuery : ILandingPageViewModelQuery
{
private ISiteRepository propertyRepo;
public LandingPageViewModelQuery(ISiteRepository pr)
{
propertyRepo = pr;
}
[SiteChrome]
public virtual ILandingPageViewModel Get()
{
var vm = new LandingPageViewModel();
return vm;
}
}
Finally here's the Intercept Attribute which I would have expected to have fired.
[AttributeUsage(AttributeTargets.Method, Inherited = true)]
public class SiteChrome : InterceptAttribute
{
public override IInterceptor CreateInterceptor(IProxyRequest request)
{
return request.Kernel.Get<SiteChromeInterceptor>();
}
}
Chris,
Do you need to add anything in the AppStart? So when using ninject you have to create and register module in appstart here is what my app start looks like for an mvc project i have where i use ninject may be something similar is needed to register intercept attributes? Just a theory btw :-}
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(TEF.Web.App_Start.NinjectWebCommon), "Stop")]
namespace TEF.Web.App_Start { using System; using System.Web;
}
Thanks Ismail, turned out I needed an extra reference to Ninject.Extensions.Interception.DynamicProxy, once that was added the interceptor attributes started working!
is working on a reply...