예제 #1
0
        public static ModularApplicationBuilder UseStaticFilesModules(this ModularApplicationBuilder modularApp)
        {
            modularApp.Configure(app =>
            {
                var extensionManager = app.ApplicationServices.GetRequiredService <IExtensionManager>();
                var env = app.ApplicationServices.GetRequiredService <IHostingEnvironment>();

                // TODO: configure the location and parameters (max-age) per module.
                var availableExtensions = extensionManager.GetExtensions();
                foreach (var extension in availableExtensions)
                {
                    var contentPath = extension.ExtensionFileInfo.PhysicalPath != null
                        ? Path.Combine(extension.ExtensionFileInfo.PhysicalPath, "Content")
                        : null;

                    var contentSubPath = Path.Combine(extension.SubPath, "Content");

                    if (env.ContentRootFileProvider.GetDirectoryContents(contentSubPath).Exists)
                    {
                        IFileProvider fileProvider;
                        if (env.IsDevelopment())
                        {
                            var fileProviders = new List <IFileProvider>();
                            fileProviders.Add(new ModuleProjectContentFileProvider(env, contentSubPath));

                            if (contentPath != null)
                            {
                                fileProviders.Add(new PhysicalFileProvider(contentPath));
                            }
                            else
                            {
                                fileProviders.Add(new ModuleEmbeddedFileProvider(env, contentSubPath));
                            }

                            fileProvider = new CompositeFileProvider(fileProviders);
                        }
                        else
                        {
                            if (contentPath != null)
                            {
                                fileProvider = new PhysicalFileProvider(contentPath);
                            }
                            else
                            {
                                fileProvider = new ModuleEmbeddedFileProvider(env, contentSubPath);
                            }
                        }

                        app.UseStaticFiles(new StaticFileOptions
                        {
                            RequestPath  = "/" + extension.Id,
                            FileProvider = fileProvider
                        });
                    }
                }
            });

            return(modularApp);
        }
        public static IApplicationBuilder ConfigureModules(this IApplicationBuilder app, Action <ModularApplicationBuilder> modules)
        {
            var modularApplicationBuilder = new ModularApplicationBuilder(app);

            modules(modularApplicationBuilder);

            return(app);
        }
예제 #3
0
        public static ModularApplicationBuilder UseNancyModules(this ModularApplicationBuilder modularApp)
        {
            modularApp.Configure(app =>
            {
                app.UseOwin(x => x.UseNancy(no =>
                {
                    var contextAccessor =
                        app.ApplicationServices.GetRequiredService <IHttpContextAccessor>();

                    no.Bootstrapper = new ModularNancyBootstrapper(
                        new[] {
                        (IAssemblyCatalog) new DependencyContextAssemblyCatalog(),
                        (IAssemblyCatalog) new AmbientAssemblyCatalog(contextAccessor)
                    });
                }));
            });

            return(modularApp);
        }
        public static ModularApplicationBuilder UseStaticFilesModules(this ModularApplicationBuilder modularApp)
        {
            modularApp.Configure(app =>
            {
                var extensionManager = app.ApplicationServices.GetRequiredService <IExtensionManager>();

                // TODO: configure the location and parameters (max-age) per module.
                var availableExtensions = extensionManager.GetExtensions();
                foreach (var extension in availableExtensions)
                {
                    var contentPath = Path.Combine(extension.ExtensionFileInfo.PhysicalPath, "Content");
                    if (Directory.Exists(contentPath))
                    {
                        app.UseStaticFiles(new StaticFileOptions
                        {
                            RequestPath  = "/" + extension.Id,
                            FileProvider = new PhysicalFileProvider(contentPath)
                        });
                    }
                }
            });

            return(modularApp);
        }