简体   繁体   中英

Method Not Found when using LightInject with MVC5 and .Net 4.5

When setting up LightInject for an MVC controller I am getting an error when calling container.EnableMvc(); in the injector setup.

Error:

Method not found: 'Void LightInject.WebContainerExtensions.EnablePerWebRequestScope(LightInject.IServiceContainer)'

Source:

public static void Register() {
    var container = new ServiceContainer();
    container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider();
    WebContainerExtensions.EnablePerWebRequestScope(container);
    container.RegisterControllers();

    container.Register<ISomeClass, SomeClass>();

    container.EnableMvc();
}

Additional Information:

  • I am running the code locally through Visual Studio
  • The project is 4.5
  • My OS is Windows 10 (framework 4.5)

In the past when I have setup LightInject I have set the scope lifetime manually but the documentation, for general setup and MVC specific examples, has since changed. I came across one thread that mentioned this could be an issue with not including LightInject.Web as a dep, but I can see it listed as a dep for LightInject.MVC and in the list of references in the project.

Are there any other steps I can take to manually configure the lifetime or otherwise verify that this method is available before Enabling MVC?

The issue here was that I installed LightInject.MVC with NuGet. It lists it's dependencies as:

LightInject.Web (>= 1.0.0.4)
LightInject (>= 3.0.1.7)

The after I exhausted this being an issue with versions of .Net 4.5 and possible issues with async. I decided to manually update both LightInject.Web and LightInject to their newest versions. After the update it resolved the issue.

I will add this as a bug in the listed dependencies on the projects site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM