/// <summary> /// 指定筛选器,自动映射类型。 /// </summary> /// <param name="container">服务容器。</param> /// <param name="mapFilter">依赖注入与控制反转的映射筛选器。</param> /// <param name="expectTypeHandler">找到预期类型时发生。</param> public static void AutoMap(this IIocContainer container, IMapFilter mapFilter, Action <Type> expectTypeHandler = null) { if (mapFilter == null) { throw new ArgumentNullException("mapFilter"); } var allTypes = ObjectFactory.AllTypes; var hasHandler = expectTypeHandler != null; foreach (var item in allTypes) { foreach (var expectType in item.Value) { var ns = expectType.Namespace; if (mapFilter.IsExpectType(expectType)) { var actualType = mapFilter.FindActualType(allTypes, expectType); if (actualType == null) { throw new Exception("无法找到预期定义类型“" + expectType.AssemblyQualifiedName + "”的实际映射类型。"); } container.AddService(expectType, actualType, mapFilter.IsSingletonMode(expectType, actualType)); if (hasHandler) { expectTypeHandler(expectType); } break; } } } }
public static IMapFilter bindTo_IMapFilter(IComponentIntrospect component) { global::System.IntPtr cPtr = solarPINVOKE.bindTo_IMapFilter(IComponentIntrospect.getCPtr(component)); IMapFilter ret = (cPtr == global::System.IntPtr.Zero) ? null : new IMapFilter(cPtr, true); if (solarPINVOKE.SWIGPendingException.Pending) { throw solarPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }