コード例 #1
0
        public static IApplicationBuilder MystiqueRoute(this IApplicationBuilder app, IHostApplicationLifetime lifetime)
        {
            lifetime.ApplicationStopping.Register(() =>
            {
                var json = JsonConvert.SerializeObject(PluginsLoadContexts.GetPlugins(all: true).Select(o =>
                {
                    o.PluginContext = null;
                    return(o);
                }));
                var pluginFolder = Path.Combine(Environment.CurrentDirectory, "host_plugins", "plugins_cache.json");
                File.WriteAllText(pluginFolder, json, Encoding.UTF8);
            });

            app.UseStaticFiles();

            app.UseRouting();

            app.UseEndpoints(routes =>
            {
                routes.MapControllerRoute(
                    name: "Mystique",
                    pattern: "{controller=Home}/{action=Index}/{id?}");

                routes.MapControllerRoute(
                    name: "Plugins",
                    pattern: "{area}/{controller=Home}/{action=Index}/{id?}");
            });

            return(app);
        }