以下两段代码是否完全相同?
.RegisterType<ICrmService, CrmService>()
和
.RegisterType(typeof(ICrmService), typeof(CrmService))
答案 0 :(得分:2)
简而言之:是的,他们确实这样做了。
只需查看源代码:https://unity.codeplex.com/SourceControl/latest#source/Unity/Src/UnityContainerExtensions.cs
通用方法:
public static IUnityContainer RegisterType<TFrom, TTo>(this IUnityContainer container, params InjectionMember[] injectionMembers) where TTo : TFrom
{
Guard.ArgumentNotNull(container, "container");
return container.RegisterType(typeof(TFrom), typeof(TTo), null, null, injectionMembers);
}
非通用方法:
public static IUnityContainer RegisterType(this IUnityContainer container, Type from, Type to, params InjectionMember[] injectionMembers)
{
Guard.ArgumentNotNull(container, "container");
return container.RegisterType(from, to, null, null, injectionMembers);
}