public DashboardMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, MicrophobiaConfiguration config,
                            MicrophobiaDashboardOptions options)
 {
     _config  = config;
     _options = options ?? new MicrophobiaDashboardOptions();
     _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options);
 }
        private StaticFileMiddleware CreateStaticFileMiddleware(
            RequestDelegate next,
            IHostingEnvironment hostingEnv,
            ILoggerFactory loggerFactory,
            MicrophobiaDashboardOptions options)
        {
            var staticFileOptions = new StaticFileOptions
            {
                FileProvider = new EmbeddedFileProvider(typeof(DashboardMiddleware).GetTypeInfo().Assembly, EmbeddedFileNamespace),
            };

            return(new StaticFileMiddleware(next, hostingEnv, Options.Create(staticFileOptions), loggerFactory));
        }
Beispiel #3
0
        public static void Strap(IServiceProvider serviceProvider, Action <MicrophobiaDashboardOptions> setupAction = null)
        {
            var options = new MicrophobiaDashboardOptions();

            setupAction?.Invoke(options);

            WebHost.CreateDefaultBuilder(null)
            .ConfigureServices(servicesCollection =>
            {
                servicesCollection.ConfigureDashboardServiceProvider(serviceProvider, options.CachingOptions);
            })
            .UseStartup(typeof(DashboardStartup))
            .UseUrls($"{options.DashboardUri}")
            .Build()
            .Start();
        }
        public static IApplicationBuilder UseMicrophobiaDashboard(this IApplicationBuilder app, Action <MicrophobiaDashboardOptions> setupAction = null)
        {
            var options = new MicrophobiaDashboardOptions();

            setupAction?.Invoke(options);

            var routePrefix = options.RoutePrefix.StartsWith("/") ? options.RoutePrefix : $"/{options.RoutePrefix}";

            app.UseSignalR(route => { route.MapHub <MicrophobiaHub>($"{routePrefix}/microphobiahub"); });

            app.UseBranchedApplicationBuilder(routePrefix, services =>
            {
                services.ConfigureDashboardServiceProvider(app.ApplicationServices, options.CachingOptions);

                services.ConfigureServicesForStandaloneMicrophobiaDashboard();
            }, builderConfig => builderConfig.ConfigureApplicationForMicrophobiaDashboard(options));

            var hubContext = app.ApplicationServices.GetRequiredService <MicrophobiaHubContext>();

            hubContext.ReplaceHubContext(app.ApplicationServices.GetRequiredService <IHubContext <MicrophobiaHub> >());

            return(app);
        }
        private static IApplicationBuilder ConfigureApplicationForMicrophobiaDashboard(this IApplicationBuilder app, MicrophobiaDashboardOptions options)
        {
            app.UseMvc();

            app.UseMiddleware <DashboardMiddleware>(options);

            return(app);
        }