public void EnsureInitialized(IBuildManager buildManager) { if (_cache == null) { lock (_lockObj) { if (_cache == null) { List <Type> controllerTypes = TypeCacheUtil.GetFilteredTypesFromAssemblies( TypeCacheName, IsControllerType, buildManager ); var groupedByName = controllerTypes.GroupBy( t => t.Name.Substring(0, t.Name.Length - "Controller".Length), StringComparer.OrdinalIgnoreCase ); _cache = groupedByName.ToDictionary( g => g.Key, g => g.ToLookup( t => t.Namespace ?? String.Empty, StringComparer.OrdinalIgnoreCase ), StringComparer.OrdinalIgnoreCase ); } } } }
/// <summary> /// 將 _cache filed 初始話 /// 載入關於Controller類別 從Assemblies中 /// </summary> /// <param name="buildManager">預設使用BuildManager</param> public void EnsureInitialized(IBuildManager buildManager) { if (_cache == null) { lock (_lockObj) { if (_cache == null) { /*** * 獲得Controller類別順序如下 * 已IsControllerType(看後贅字是否是Controller) * 1.從硬碟中找尋是否有快取的Controller類別 * 2.從組件中掃描出已Controller結尾的類別,並將資料序列話存在硬碟上 **/ List <Type> controllerTypes = TypeCacheUtil.GetFilteredTypesFromAssemblies(TypeCacheName, IsControllerType, buildManager); var groupedByName = controllerTypes.GroupBy( t => t.Name.Substring(0, t.Name.Length - "Controller".Length), StringComparer.OrdinalIgnoreCase); _cache = groupedByName.ToDictionary( g => g.Key, g => g.ToLookup(t => t.Namespace ?? String.Empty, StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase); } } } }
internal static void RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, object state) { List <Type> areaRegistrationTypes = TypeCacheUtil.GetFilteredTypesFromAssemblies(TypeCacheName, IsAreaRegistrationType, buildManager); foreach (Type areaRegistrationType in areaRegistrationTypes) { AreaRegistration registration = (AreaRegistration)Activator.CreateInstance(areaRegistrationType); registration.CreateContextAndRegister(routes, state); } }