Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Registering one filter type for multiple controllers doesn't work in one statement #33

Open
smriti21 opened this issue Mar 23, 2020 · 1 comment

Comments

@smriti21
Copy link

smriti21 commented Mar 23, 2020

The issue was also in WebpApi but it is resolved. The fix is needed in Mvc as well. The following line of code doesn't work -

        builder.Register(
                ctx => c.Resolve<IProperty>())
            .AsActionFilterFor<BaseController1>()
            .AsActionFilterFor<BaseController2>()
            .InstancePerRequest();

Error: System.ArgumentException: 'An item with the same key has already been added.'

Part of Stacktrace:

   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at Autofac.Builder.RegistrationBuilder`3.WithMetadata(String key, Object value)
   at Autofac.Integration.Mvc.RegistrationExtensions.AsFilterFor[TFilter,TController](IRegistrationBuilder`3 registration, String metadataKey, Int32 order)
   at Autofac.Integration.Mvc.RegistrationExtensions.AsActionFilterFor[TController](IRegistrationBuilder`3 registration, Int32 order)
@tillig
Copy link
Member

tillig commented Mar 2, 2022

The Autofac WebAPI implementation allows for a list of predicates to determine if a given filter applies to an action. I think this could reasonably easily be adapted to the MVC side of things. I'm not sure how much time we have to allocate to it, but if folks want it, we'd accept a PR.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants