public App() { BlazorHybridHost.AddResourceAssembly(GetType().Assembly, contentRoot: "WebUI/wwwroot"); var host = MobileBlazorBindingsHost.CreateDefaultBuilder() .ConfigureServices((hostContext, services) => { // Adds web-specific services such as NavigationManager services.AddBlazorHybrid(); // Register app-specific services services.AddSingleton <CounterState>(); services.AddSingleton <AppState>(); services.AddOptions(); services.AddAuthorizationCore(); services.AddScoped <CustomStateProvider>(); services.AddScoped <AuthenticationStateProvider>(s => s.GetRequiredService <CustomStateProvider>()); services.AddScoped <IAuthService, AuthService>(); }) .Build(); MainPage = new ContentPage { Title = "My Application" }; host.AddComponent <Main>(parent: MainPage); }
public MainPage() { BlazorHybridHost.AddResourceAssembly(GetType().Assembly, contentRoot: "WebUI/wwwroot"); var serviceCollection = new ServiceCollection(); serviceCollection.AddBlazorHybrid(); serviceCollection.AddLogging(); serviceCollection.AddSingleton <AppState>(); BlazorHybridDefaultServices.Instance = serviceCollection.BuildServiceProvider(); InitializeComponent(); MasterDetails.IsPresented = false; WorkaroundDisplayIssue(); }
public App() { BlazorHybridHost.AddResourceAssembly(typeof(App).Assembly, contentRoot: "WebUI/wwwroot"); var host = MobileBlazorBindingsHost.CreateDefaultBuilder() .ConfigureServices((hostContext, services) => { services.AddBlazorHybrid(); services.AddSingleton <BlazorLib.State.CounterState>(); }) .Build(); MainPage = new ContentPage { Title = "My Application" }; host.AddComponent <Main>(parent: MainPage); }
public App() { BlazorHybridHost.AddResourceAssembly(GetType().Assembly, contentRoot: "WebUI/wwwroot"); var host = MobileBlazorBindingsHost.CreateDefaultBuilder() .ConfigureServices((hostContext, services) => { // Adds web-specific services such as NavigationManager services.AddBlazorHybrid(); // Register app-specific services services.AddSingleton <CounterState>(); }) .Build(); MainPage = new ContentPage { Title = "My Application" }; host.AddComponent <Main>(parent: MainPage); }
public App() { BlazorHybridHost.AddResourceAssembly(GetType().Assembly, contentRoot: "WebUI/wwwroot"); var host = MobileBlazorBindingsHost.CreateDefaultBuilder() .ConfigureServices((hostContext, services) => { // Adds web-specific services such as NavigationManager services.AddBlazorHybrid(); services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:44343/") }); }) .Build(); MainPage = new ContentPage { Title = "First Blazor Mobile Application" }; host.AddComponent <Main>(parent: MainPage); }
protected BlazorWebView(Dispatcher dispatcher, bool initOnParentSet) { _initOnParentSet = initOnParentSet; Content = _webView = new WebViewExtended(); _dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher)); _webView.SchemeHandlers.Add(BlazorAppScheme, (string url, out string contentType) => { var uri = new Uri(url); if (uri.Host.Equals("0.0.0.0", StringComparison.Ordinal)) { // TODO: Prevent directory traversal? var contentRootAbsolute = Path.GetFullPath(ContentRoot ?? "."); var appFile = Path.Combine(contentRootAbsolute, uri.AbsolutePath.Substring(1)); if (appFile == contentRootAbsolute) { contentType = "text/html"; const string IndexHtmlFilename = "index.html"; var indexHtmlPath = Path.Combine(contentRootAbsolute, IndexHtmlFilename); if (BlazorHybridHost.TryGetEmbeddedResourceFile(IndexHtmlFilename, out var fileStream)) { return fileStream; } else { // Use default HTML if none was provided in ContentRoot return new MemoryStream(Encoding.UTF8.GetBytes(@"<!DOCTYPE html> <html> <head> <meta charset=""utf-8"" /> <meta name=""viewport"" content=""width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"" /> <base href=""/"" /> <style type=""text/css""> #blazor-error-ui { background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000; } #blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; } </style> </head> <body> <app></app> <div id=""blazor-error-ui""> An unhandled error has occurred. <a href="""" class=""reload"">Reload</a> <a class=""dismiss"">🗙</a> </div> </body> </html> ")); } } else if (BlazorHybridHost.TryGetEmbeddedResourceFile(uri.AbsolutePath.Substring(1), out var fileStream)) { contentType = GetContentType(uri.AbsolutePath.Substring(1)); return fileStream; } } contentType = default; return null; }); // framework:// is resolved as embedded resources _webView.SchemeHandlers.Add("framework", (string url, out string contentType) => { contentType = GetContentType(url); return SupplyFrameworkFile(url); }); _ipc = new IPC(_webView); _jsRuntime = new BlazorHybridJSRuntime(_ipc); }