Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MobileBlazorBindingsHost that works on all platforms #51

Merged
merged 1 commit into from Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Microsoft.MobileBlazorBindings/MobileBlazorBindingsHost.cs
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.IO;

namespace Microsoft.MobileBlazorBindings
{
public static class MobileBlazorBindingsHost
{
public static IHostBuilder CreateDefaultBuilder()
{
// Inspired by Microsoft.Extensions.Hosting.Host, which can be seen here:
// https://github.com/dotnet/extensions/blob/master/src/Hosting/Hosting/src/Host.cs
// But slightly modified to work on all of Android, iOS, and UWP.

var builder = new HostBuilder();

builder.UseContentRoot(Directory.GetCurrentDirectory());

builder.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConsole(configure => configure.DisableColors = true);
logging.AddDebug();
logging.AddEventSourceLogger();
})
.UseDefaultServiceProvider((context, options) =>
{
var isDevelopment = context.HostingEnvironment.IsDevelopment();
options.ValidateScopes = isDevelopment;
options.ValidateOnBuild = isDevelopment;
});

return builder;
}
}
}
2 changes: 1 addition & 1 deletion templates/MobileBlazorBindings-app/NewApp/App.cs
Expand Up @@ -9,7 +9,7 @@ public class App : Application
{
public App()
{
var host = Host.CreateDefaultBuilder()
var host = MobileBlazorBindingsHost.CreateDefaultBuilder()
.ConfigureServices((hostContext, services) =>
{
// Register app-specific services
Expand Down