English 中文(简体)
• 如何注入带有汽车舱面3的全球过滤财产?
原标题:how to injection a global filter property with autofac mvc3?
  • 时间:2011-10-31 08:06:59
  •  标签:
  • autofac

builder.RegisterFilterProvider();

它可以在过滤器上注入一种财产,如:

[TestFilter]
public ActionResult SomeAction(){...}

But can not inject a global filter register at global.asax like

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{

    filters.Add(new TestFilterAttribute());

}

我怎么做呢?

最佳回答

• 在登记全球过滤器时确定该财产。

filters.Add(new TestFilterAttribute() { TObj=AutofacDependencyResolver.Current.ApplicationContainer.Resolve<ITest>() });

i 尝试某种方式

builder.RegisterType<TestFilterAttribute>().PropertiesAutowired()

builder.RegisterType<TestFilterAttribute>().OnActivating(x=>x.Instance.TObj=x.Context.Resolve<ITest>())

builder.RegisterType<TestFilterAttribute>().WithProperty("TObj",new Test())

以上不是工作

builder.RegisterType<TestFilterAttribute>().PropertiesAutowired();

并用诸如:

filters.Add(AutofacDependencyResolver.Current.ApplicationContainer.Resolve<TestFilterAttribute>());
问题回答

暂无回答




相关问题
Registering Collections in Autofac 2.1.10 RC

I am upgrading code from Autofac 1.4 to 2.1.10 Release Candidate. My module previously performed registration like this: builder.RegisterCollection<IExceptionHandler>() .As<...

How to carry out custom initialisation with autofac

I m adding autofac to an existing project and some of the service implementations require their Initialize method to be called and passed configuration information. Currently I m using the code: ...

Autofac doesn t like MVC Source

I added the ASP.NET MVC 2 RC2 source code to my solution (using these instructions: http://blog.stevensanderson.com/2009/02/03/using-the-aspnet-mvc-source-code-to-debug-your-app/), but now it won t ...

IOC/Autofac container

I am currently using Autofac, but am open to commentary regarding other IOC containers as well. I would prefer a solution using Autofac if possible. I am also somewhat new to IOC so I may be grossly ...

Dependency Injection for Presenter

I have a Presenter that takes a Service and a View Contract as parameters in its constructor: public FooPresenter : IFooPresenter { private IFooView view; private readonly IFooService service;...

热门标签