Exemplo n.º 1
0
        /// <summary>
        /// Gets the FileHandler with a specific name
        /// </summary>
        /// <param name="services">the serviceprovider that holds injectable services</param>
        /// <param name="rawName">the expected raw-name of the file-handler</param>
        /// <returns>the requested instance when it was found.</returns>
        public static object GetFileHandler(this IServiceProvider services, string rawName)
        {
            IWebPluginHelper plugins = services.GetService <IWebPluginHelper>();
            IPermissionScope scope   = services.GetService <IPermissionScope>();
            var name    = $"{scope?.PermissionPrefix}{rawName}";
            var factory = plugins.GetFactory();
            var retVal  = factory[name, true];

            if (retVal == null)
            {
                retVal = factory[rawName, true];
            }

            if (retVal is IAsyncFileHandler afh)
            {
                return(afh);
            }

            if (retVal is IFileHandler sfh)
            {
                return(sfh);
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers a Factory that resolves Db-Contexts through the Plugin-Environment
        /// </summary>
        /// <param name="options">the foreign-key options object</param>
        /// <param name="usePermissionScope">indicates whether to use the permission-scope</param>
        /// <returns>the provided options-object for method-chaining</returns>
        public static T UsePlugins <T>(this T options, bool usePermissionScope = true) where T : ContextResolveOptions
        {
            return((T)options.RegisterService("*", (provider, s, area) =>
            {
                IWebPluginHelper plugins = provider.GetService <IWebPluginHelper>();
                IPermissionScope scope = null;
                if (usePermissionScope)
                {
                    scope = provider.GetService <IPermissionScope>();
                }

                var name = $"{scope?.PermissionPrefix}{area}{s}";
                var factory = plugins.GetFactory();
                var retVal = factory[name, true];
                if (retVal == null)
                {
                    name = $"{scope?.PermissionPrefix}{s}";
                    retVal = factory[name, true];
                }
                if (retVal == null)
                {
                    retVal = factory[s, true];
                }

                return retVal;
            }));
        }