什么是StructureMap的For <t>()的Unity等效项。Use(SomeThing)

时间:2019-01-09 01:44:47

标签: c# unity-container structuremap

假设我有一个IUnityContainer的实例,如何将这个StructureMap Registry转换为Unity?

public class MvcRegistry : Registry
{
    public MvcRegistry()
    {
        For<BundleCollection>().Use(BundleTable.Bundles);
        For<RouteCollection>.Use(RouteTable.Routes);
    }
}

例如,...

public static class UnityContainerExtensions
{
    public static IUnityContainer RegisterMvcComponents(this IUnityContainer container)
    {
        // similar to this:
        container.RegisterType(typeof(BundleCollection), BundleTable.Bundles)
        return container;
    }
}

...这是不对的,但是您理解了我的意思...

1 个答案:

答案 0 :(得分:1)

RegisterInstance方法:

container.RegisterInstance<BundleCollection>(BundleTable.Bundles)