Skip to content
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

Mvc Resolver is not "attaching" as expected. #17

Open
djseng opened this issue Sep 4, 2020 · 12 comments
Open

Mvc Resolver is not "attaching" as expected. #17

djseng opened this issue Sep 4, 2020 · 12 comments
Labels
bug Something isn't working fix-verification-needed Issue is now fixed in latest release, needs OP to confirm it's fixed for them at their end.

Comments

@djseng
Copy link
Contributor

djseng commented Sep 4, 2020

I tried the AddMvcDependencyResolver as demonstrated in the GETTING_STARTED.md but it does not appear to work as expected.

I added the Mvc Package (have been using the base fine in this web forms project for a couple of weeks now).

    public static class ApplicationStart
    {
        private static ApplicationDependencyInjection resolver;

        public static void PreStart()
        {
            resolver = new ApplicationDependencyInjectionBuilder()
                .ConfigureServices(ConfigureServices)
                .AddMvcDependencyResolver()
                .Build();

            Debug.WriteLine("CurrentResolver: " + 
                System.Web.Mvc.DependencyResolver.Current.GetType().FullName); // <-- this outputs the type for the default mvc resolver.
        }

        private static void ConfigureServices(IServiceCollection services) { /* unrelated */ }
}
@djseng
Copy link
Contributor Author

djseng commented Sep 4, 2020

I think the DependencyInjectionMvcDependencyResolver ctor is missing a call to DependencyResolver.SetResolver( this );

@daiplusplus
Copy link
Owner

Hmm, good catch!

I do remember my unit and integration tests for ASP.NET MVC passing though - I need to find out why those tests were passing when something like this should surely mean they shouldn't pass, hmm.

I'll report back soon.

@watfordgnf
Copy link

It seems the same is true for WebApi. Nothing is setting up the DependencyResolver for that client, and I can't quite get it out of the injected space.

@watfordgnf
Copy link

I've added the fix for WebAPI support in #25.

@StandBackBurrito
Copy link

We are running into the same issue for WebAPI, any updates on this?

@daiplusplus
Copy link
Owner

Do any of you have a project that reproduces the issue that you can put in an emailed zip or github gist or repo?

@daiplusplus
Copy link
Owner

daiplusplus commented May 25, 2021

@StandBackBurrito ASP.NET Web API uses a different mini-resolver class than ASP.NET MVC. The code in this thread is specific to ASP.NET MVC. Can you explain how your ASP.NET Web API project is using ASP.NET MVC's resolver?

  • ASP.NET MVC uses System.Web.Mvc.IDependencyResolver.
  • ASP.NET Web API uses System.Web.Http.Dependencies.IDependencyResolver.

@StandBackBurrito
Copy link

I was responding to @watfordgnf comment and the changes he made in #25.
Let me see if I can create a minimal repro.

@StandBackBurrito
Copy link

@Jehoel I have created a project setup the same way ours is. It has a VB webforms app with some webapi controllers.
The DI setup is done in a C# in another project.

https://github.com/StandBackBurrito/WebApiDIRepro

Let me know if you have any questions
thanks

@daiplusplus
Copy link
Owner

daiplusplus commented Jul 19, 2021

@djseng

@StandBackBurrito

I've just published version 5.0.0-beta01 which I think fixes this issue - can you verify that at your end?

https://www.nuget.org/packages/Jehoel.AspNetDependencyInjection/5.0.0-beta01

https://www.nuget.org/packages/Jehoel.AspNetDependencyInjection.Mvc/5.0.0-beta01

@daiplusplus daiplusplus added bug Something isn't working fix-verification-needed Issue is now fixed in latest release, needs OP to confirm it's fixed for them at their end. labels Aug 7, 2021
@mohaaron
Copy link

mohaaron commented Nov 12, 2021

Hey all,

Was this ever resolved? I have added and configured this package in an ASP.NET Web Forms project and all is good, but I just added MVC and now get this error when executing a controller.

"No parameterless constructor defined for this object"

UPDATE

I just installed 5.0.0-beta02 and my MVC controller injection is working. Good work and thank you!

@pl-jcarter
Copy link

I've been testing 5.0.0-beta02 in a .net 4.7.2 project and MVC controller injection is working.
@daiplusplus Any plans to publish a release version without the beta tag?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix-verification-needed Issue is now fixed in latest release, needs OP to confirm it's fixed for them at their end.
Projects
None yet
Development

No branches or pull requests

6 participants