-
Notifications
You must be signed in to change notification settings - Fork 12
CustomFilterProvider #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Looks like adding the line services.Remove(new ServiceDescriptor(typeof(IFilterProvider), typeof(DefaultFilterProvider),
ServiceLifetime.Singleton)); before adding the custom FilterProvider replaced the default provider. I'm now working on making it the The full method is now: public static void AddCustomFilterProvider(this IServiceCollection services,
Func<Type, object> provider)
{
if (services == null) throw new ArgumentNullException(nameof(services));
if (provider == null) throw new ArgumentNullException(nameof(provider));
services.Remove(new ServiceDescriptor(typeof(IFilterProvider), typeof(DefaultFilterProvider),
ServiceLifetime.Singleton));
services.TryAddEnumerable(ServiceDescriptor.Singleton<IFilterProvider>(
new DelegatingFilterProvider(provider)));
} |
I've been digging into the ASP.NET Core code, but I have yet to grok how the filter activation is happening. There's a lot of layers of misdirection/abstraction and I can only gather that IServiceProvider is tightly coupled to creating a new filter object. Any help would be appreciated. |
This whole model of adding, replacing and trying to replace registrations is built on quick sand. The order in which you make the calls is crucial, but completely depending on the internal implementation. Most of the time you can simply make your replacing registration after calling This model however completely breaks in case the framework resolved the abstraction as a collection, as is the case with What happens when you have two filter providers is unclear to me. What probably happens is that the public virtual void ProvideFilter(FilterProviderContext context, FilterItem filterItem)
{
if (filterItem.Filter != null)
{
return;
} I must admit that I have no experience with filter providers in ASP.NET Core myself, so I'm not sure whether I can provide you with any information that is of any use to you. |
Thanks for the input @dotnetjunkie. I spent a lot of time trying to replace the built-in DI framework in ASP.NET Core using the files in this repo, but there seems to be a number of issues as you outlined, including filter injection. Honestly, at this point, I think the only reliable route is to follow in the footsteps of Autofac and other DI containers and create an adapter. Unfortunately, Ninject doesn't seem to be actively maintained and we might have to write a bit of code to get it working with ASP.NET Core. |
I surely don't advice you to go this route. Having seen the amount of pain the Autofac maintainers have gone through, I think it is safe to say that it is undoable for a non-maintainer to build a reliable adapter; at this point, it's unclear whether the maintainers of Ninject would be able to succeed.
Don't try to "replace the built-in DI framework". You should leave it as-is. Leave it in for all framework stuff and only plugin your container to resolve application components. I agree this isn't ideal at the moment, due to the lacking design of ASP.NET Core, but going the Conforming Container root will not solve your problems at all. I'm afraid we will have to bite the bullet on this one. After we know where the flaws and shortcomings are, we can communicate this to Microsoft and they can improve their design to minimize the pain for us. |
Thank you for creating this repo and pushing Microsoft to add more flexibility in choice of containers.
Using the sample Ninject, project, I set everything up but I'm getting an error when I try to resolve/active a filter of type
IAuthorizationFilter
which depends on a types in my container.Is there a way to replace the activator for filters? I tried to replace the
IFilterProvider
via:But I wasn't able to get a breakpoint in
DelegatingFilterProvider
to hit.DelegatingFilterProvider
just inherits fromDefaultFilterProvider
at the moment.Here's the relevant part of the exception:
Any thoughts on how to do that?
The text was updated successfully, but these errors were encountered: