在 UnityContainer 中找不到 Resolve<T> 方法

Cannot find the Resolve<T> method in UnityContainer

根据MSDNUnityContainerclass的Resolve<T>()方法使用如下:

var controller = container.Resolve<ManagementController>();

但是,我在 UnityContainer class 定义中找不到该方法。我只能看到这个:

public class UnityContainer : IUnityContainer, IDisposable
{
    // Other methods
    public object Resolve(Type t, string name, params ResolverOverride[] resolverOverrides);
    public IEnumerable<object> ResolveAll(Type t, params ResolverOverride[] resolverOverrides);
    // Other methods
}

我是不是用错了包之类的?

这些是我安装的包。

using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration; 

IUnityContainer.Resolve<T>()是扩展方法:

https://msdn.microsoft.com/en-us/library/microsoft.practices.unity.unitycontainerextensions(v=pandp.30).aspx

在Visual Studio中,将光标放在Resolve<T>方法上,然后按F12,它将转到:UnityContainerExtensions

是一个扩展方法,需要的话代码here

它在 UnityContainerExtensions 中 class。正如@CodingYoshi 提到的,如果您执行 F12 或转到 definition ,您会发现整个 class.

这里是 class.

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

    namespace Microsoft.Practices.Unity
    {
        //
        // Summary:
        //     Extension class that adds a set of convenience overloads to the Microsoft.Practices.Unity.IUnityContainer
        //     interface.
        public static class UnityContainerExtensions
        {
            //
        // Summary:
        //     Resolve an instance of the default requested type from the container.
        //
        // Parameters:
        //   container:
        //     Container to resolve from.
        //
        //   overrides:
        //     Any overrides for the resolve call.
        //
        // Type parameters:
        //   T:
        //     System.Type of object to get from the container.
        //
        // Returns:
        //     The retrieved object.
        public static T Resolve<T>(this IUnityContainer container, params ResolverOverride[] overrides);
        //
        // Summary:
        //     Resolve an instance of the requested type with the given name from the container.
        //
        // Parameters:
        //   container:
        //     Container to resolve from.
        //
        //   name:
        //     Name of the object to retrieve.
        //
        //   overrides:
        //     Any overrides for the resolve call.
        //
        // Type parameters:
        //   T:
        //     System.Type of object to get from the container.
        //
        // Returns:
        //     The retrieved object.
        public static T Resolve<T>(this IUnityContainer container, string name, params ResolverOverride[] overrides);
        //
        // Summary:
        //     Return instances of all registered types requested.
        //
        // Parameters:
        //   container:
        //     Container to resolve from.
        //
        //   resolverOverrides:
        //     Any overrides for the resolve calls.
        //
        // Type parameters:
        //   T:
        //     The type requested.
        //
        // Returns:
        //     Set of objects of type T.
        //
        // Remarks:
        //     This method is useful if you've registered multiple types with the same System.Type
        //     but different names.
        //     Be aware that this method does NOT return an instance for the default (unnamed)
        //     registration.


public static IEnumerable<T> ResolveAll<T>(this IUnityContainer container, params ResolverOverride[] resolverOverrides);


        }
    }