简体   繁体   中英

What's the Unity equivalent of StructureMap's For<T>().Use(SomeThing)

Assuming I have an instance of IUnityContainer to work with, how would I translate this StructureMap Registry into Unity?

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

so, for example...

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

... which isn't right, but you get my meaning...

RegisterInstance方法:

container.RegisterInstance<BundleCollection>(BundleTable.Bundles)

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