IUnityContainer.Resolve throws error claiming it cannot be used with type parameters

前端 未结 5 771
陌清茗
陌清茗 2020-12-22 23:46

Yesterday I\'ve implemented the code:

CustomerProductManager productsManager = container.Resolve();

It was co

相关标签:
5条回答
  • 2020-12-23 00:00

    In my situation the class I was wrapping with Unity inherited from an abstract base class, and that base class did NOT have a parameterless constructor. Once I changed my code to use a parameterless constructor for the base class, the problem disappeared.

    0 讨论(0)
  • 2020-12-23 00:09

    Microsoft no longer owns Unity and it's in version 5, the namespace is now:

    using Unity;
    

    Ensure that is in your using section when using:

    container.Resolve<T>();
    
    0 讨论(0)
  • 2020-12-23 00:17

    In my situation, I had Bootstrapper implement its own Resolve without the generic version, so it couldn't find the Microsoft's Unity Resolve. Adding the proper usings did the trick.

    0 讨论(0)
  • 2020-12-23 00:18

    I faced this problem and none of this answers did not help me. I was getting the compile time error

    Unknown method RegisterType() of Microsoft.Practices.Unity.IUnityContainer

    for my below code.

    Container.RegisterType<IMyInterface, MyClass>();

    I found that if you did not implement IMyInterface to the class MyClass, you get this issue. Hope it resolves for you too...

    0 讨论(0)
  • 2020-12-23 00:19

    I had the same problem and found the "fix" looking at Prism sample code files. Looks like, even if it is not a dll in Unity V2 you have to add a reference in your class to: Microsoft.Practices.Unity

    my complete "using" section is as follow

    using System;
    using System.Windows;
    using Microsoft.Practices.Composite.Modularity;
    using Microsoft.Practices.Unity;
    using Microsoft.Practices.Composite.UnityExtensions;
    

    I'm not sure if you are using Silverlight, but the generic version for Container.Resolve IS in Microsoft.Practices.Unity.

    0 讨论(0)
提交回复
热议问题