dongfo / autofac

Automatically exported from code.google.com/p/autofac
0 stars 0 forks source link

2.5.1.827 does not inject action filters #335

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Use the current (just released) version of Autofac (2.5.1.827)
2. Register ExtensibleActionInvoker and Controllers, along with resource to be 
injected (omitted from example below)

    builder.RegisterType<ExtensibleActionInvoker>()
        .As<IActionInvoker>();
        //.WithParameter("injectActionMethodParameters", true);

    builder.RegisterControllers(_controllerAssembly)
       .InjectActionInvoker()
       .PropertiesAutowired()
       .OnActivated(e => {
                        if (_onControllerActivication != null)
                        {
                            _onControllerActivication(e);
                        }
        });

Note: This is being registered in a MvcModule I wrote (also registering 
AutofacWebTypesModule and ViewRegistrationSource).

3. Attempt to access property in action filter that should be injected

What is the expected output? What do you see instead?
Property is null instead of instance.

What version of Autofac are you using? 2.5.1.827
On what version of .NET/Silverlight? .NET 4.0

Please provide any additional information below.
I reverted back to 2.4.5.724 (including Autofac.Integration.Mvc) and action 
filter properties are injected again.

I tried building the ExtensibleActionInvoker registration with and without the 
".WithParameter("injectActionMethodParameters", true)" configuration without 
success.

Original issue reported on code.google.com by techniq35 on 14 Jul 2011 at 3:40

GoogleCodeExporter commented 8 years ago
Hi - looks like you spotted a breaking change that I missed in the release 
notes.

As far as I understand it, you need to register AutofacWebTypesModule for this 
behavior to apply in the new version (this fixes a bug discovered in the 2.4 
code.)

Alex will be able to confirm; if this is indeed the case I'll post some further 
release notes.

Thanks very much for letting us know.

Nick

Original comment by nicholas...@gmail.com on 15 Jul 2011 at 2:56

GoogleCodeExporter commented 8 years ago
Hmm.. I already have the AutofacWebTypesModules registered as part of my 
"MvcModule".  Here is the full Load(ContainerBuilder builder) of my module.

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterModule(new AutofacWebTypesModule());
            builder.RegisterSource(new ViewRegistrationSource());
            builder.RegisterType<ExtensibleActionInvoker>()
                .As<IActionInvoker>();
                //.WithParameter("injectActionMethodParameters", true);

            builder.RegisterControllers(_controllerAssembly)
                .InjectActionInvoker()
                .PropertiesAutowired()
                .OnActivated(e =>
                {
                    if (_onControllerActivication != null)
                    {
                        _onControllerActivication(e);
                    }
                });
        }

If I can provide any more information that will help, just let me know.

Original comment by techniq35 on 15 Jul 2011 at 3:07

GoogleCodeExporter commented 8 years ago
Thanks for the extra information, I'll take a look ASAP.

Original comment by nicholas...@gmail.com on 19 Jul 2011 at 11:25

GoogleCodeExporter commented 8 years ago
Sorry for jumping in so late.

You should be able to use the new filter provider to perform property injection 
on your attributes. I blogged about it at the link below but obviously didn’t 
get around to updating the wiki.

http://alexmg.com/post/2011/03/24/FilterAttribute-Property-Injection-in-Autofac-
MVC-3-Integration.aspx

I'll add some information about this onto the wiki to help avoid confusion in 
the future.

Original comment by alex.meyergleaves on 2 Aug 2011 at 11:58

GoogleCodeExporter commented 8 years ago
Thanks Alex

Original comment by techniq35 on 3 Aug 2011 at 2:37