/// <summary>
        /// Resolves class types inheriting from or implementing the specified type and marked with the specified attribute.
        /// </summary>
        /// <typeparam name="T">The type to inherit from or implement.</typeparam>
        /// <typeparam name="TAttribute">The type of the attribute.</typeparam>
        /// <param name="cache">Indicates whether to use cache for type resolution.</param>
        /// <param name="specificAssemblies">A set of assemblies for type resolution.</param>
        /// <returns>All class types inheriting from or implementing the specified type and marked with the specified attribute.</returns>
        /// <remarks>Caching is disabled when using specific assemblies.</remarks>
        public IEnumerable <Type> ResolveTypesWithAttribute <T, TAttribute>(bool cache = true, IEnumerable <Assembly> specificAssemblies = null)
            where TAttribute : Attribute
        {
            // do not cache anything from specific assemblies
            cache &= specificAssemblies == null;

            // if not caching, or not IDiscoverable, directly resolve types
            if (cache == false || typeof(IDiscoverable).IsAssignableFrom(typeof(T)) == false)
            {
                return(ResolveTypesInternal(
                           typeof(T), typeof(TAttribute),
                           () => TypeFinder.FindClassesOfTypeWithAttribute <T, TAttribute>(specificAssemblies ?? AssembliesToScan),
                           cache));
            }

            // if caching and IDiscoverable
            // filter the cached discovered types (and cache the result)

            var discovered = ResolveTypesInternal(
                typeof(IDiscoverable), null,
                () => TypeFinder.FindClassesOfType <IDiscoverable>(AssembliesToScan),
                true);

            return(ResolveTypesInternal(
                       typeof(T), typeof(TAttribute),
                       () => discovered
                       .Where(x => typeof(T).IsAssignableFrom(x))
                       .Where(x => x.GetCustomAttributes <TAttribute>(false).Any()),
                       true));
        }
Пример #2
0
 /// <summary>
 /// Generic method to find the specified type and cache the result
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public IEnumerable <Type> ResolveTypes <T>(bool cacheResult = true, IEnumerable <Assembly> specificAssemblies = null)
 {
     return(ResolveTypes <T>(
                () => TypeFinder.FindClassesOfType <T>(specificAssemblies ?? AssembliesToScan),
                TypeResolutionKind.FindAllTypes,
                cacheResult));
 }
Пример #3
0
 /// <summary>
 /// Generic method to find the specified type and cache the result
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 internal IEnumerable <Type> ResolveTypes <T>(bool cacheResult = true)
 {
     return(ResolveTypes <T>(
                () => TypeFinder.FindClassesOfType <T>(AssembliesToScan),
                TypeResolutionKind.FindAllTypes,
                cacheResult));
 }
Пример #4
0
        /// <summary>
        /// This is used when an IAction or IActionHandler is installed into the system
        /// and needs to be loaded into memory.
        /// </summary>
        /// <remarks>
        /// TODO: this shouldn't be needed... we should restart the app pool when a package is installed!
        /// </remarks>
        public static void ReRegisterActionsAndHandlers()
        {
            lock (Lock)
            {
                //TODO: Based on the above, this is a big hack as types should all be cleared on package install!
                ActionsResolver.Reset();
                ActionHandlers.Clear();

                //TODO: Based on the above, this is a big hack as types should all be cleared on package install!
                ActionsResolver.Current = new ActionsResolver(
                    () => TypeFinder.FindClassesOfType <IAction>(PluginManager.Current.AssembliesToScan));

                RegisterIActionHandlers();
            }
        }
Пример #5
0
        /// <summary>
        /// This is used when an IAction or IActionHandler is installed into the system
        /// and needs to be loaded into memory.
        /// </summary>
        /// <remarks>
        /// TODO: this shouldn't be needed... we should restart the app pool when a package is installed!
        /// </remarks>
        public static void ReRegisterActionsAndHandlers()
        {
            lock (Lock)
            {
                using (Umbraco.Core.ObjectResolution.Resolution.DirtyBackdoorToConfiguration)
                {
                    //TODO: Based on the above, this is a big hack as types should all be cleared on package install!
                    ActionsResolver.Reset(false); // and do NOT reset the whole resolution!
                    ActionHandlers.Clear();

                    //TODO: Based on the above, this is a big hack as types should all be cleared on package install!
                    ActionsResolver.Current = new ActionsResolver(
                        () => TypeFinder.FindClassesOfType <IAction>(PluginManager.Current.AssembliesToScan));

                    RegisterIActionHandlers();
                }
            }
        }
Пример #6
0
        /// <summary>
        /// This is used when an IAction or IActionHandler is installed into the system
        /// and needs to be loaded into memory.
        /// </summary>
        /// <remarks>
        /// TODO: this shouldn't be needed... we should restart the app pool when a package is installed!
        /// </remarks>
        public static void ReRegisterActionsAndHandlers()
        {
            lock (Lock)
            {
                // NOTE use the DirtyBackdoor to change the resolution configuration EXCLUSIVELY
                // ie do NOT do ANYTHING else while holding the backdoor, because while it is open
                // the whole resolution system is locked => nothing can work properly => deadlocks

                var newResolver = new ActionsResolver(
                    new ActivatorServiceProvider(), LoggerResolver.Current.Logger,
                    () => TypeFinder.FindClassesOfType <IAction>(PluginManager.Current.AssembliesToScan));

                using (Umbraco.Core.ObjectResolution.Resolution.DirtyBackdoorToConfiguration)
                {
                    ActionsResolver.Reset(false); // and do NOT reset the whole resolution!
                    ActionsResolver.Current = newResolver;
                }
            }
        }