-
Notifications
You must be signed in to change notification settings - Fork 19
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
Less handler fails in conjunction with 'Microsoft.Extensions.DependencyInjection' v8 #82
Comments
Hello, Juliano! Bundle Transformer and Microsoft.Extensions.DependencyInjection are things from different worlds. I do not recommend that you even try to create a instances of the Bundle Transformer's types through DI. I got feeling that you are trying to use the |
I would've agreed with you a few years ago, but not anymore. As you can see, we have a WebForms project that leverages your Less handler via standard web.config setup, and then we added dependency injection support to that project once it became available. WebForms with DI enabled will attempt to resolve every object through the DI container, including ones defined via configuration like this.
I'm not sure I understand what you are saying there (to be fair, I don't know the precise history of when/how this handler was added to our project, it was probably a very long time ago), but I've since resolved the problem with a modification to our implementation of the The only reason I decided to create this issue was to make you aware of the problem (I do consider it a problem), but if you disagree, do feel free and close the issue. |
Could you please provide a link to the documentation or article that describes this approach in ASP.NET Web Forms. |
This is a blog post from back when it was first made available. It uses the Unity container but you can use any other container (we use Autofac on our side, for instance): And this is the relevant bits that I mentioned:
|
Thanks for information! |
The Less request handler (
BundleTransformer.Less.HttpHandlers.LessAssetHandler
) defines 2 public constructors:BundleTransformer/src/BundleTransformer.Less/HttpHandlers/LessAssetHandler.cs
Lines 30 to 49 in 82a1beb
This breaks when attempting to resolve the handler through DI when using Microsoft.Extensions.DependencyInjection v8, as a breaking change was introduced that now throws an
InvalidOperationException
when multiple valid constructors are found.Section of a stacktrace from our WebForms app which uses Autofac through MEDI:
And how we are configuring the handler in the
web.config
:Here is the documentation regarding the breaking change in MEDI v8 that explains the issue in more detail:
This likely breaks with other containers or setups as well since depending on the DI adapter implementation, it could just call directly into a build-up method in the DI library and many DI libraries will choke when multiple public constructors are found.
In our setup, we should be able to workaround this issue by manually registering the handler using a factory registration, but you might still want to reconsider the design here and opt to have just a single constructor (and maybe move the second one into a factory class).
The text was updated successfully, but these errors were encountered: