コード例 #1
0
 public static IXamarinHostBuilder UseNavigationMiddleware(this IXamarinHostBuilder builder, Action <RemovePageDelegate, NavigationContext> action)
 {
     return(builder.ConfigureNavigation((ctx, sp, sb) =>
     {
         sb.UseMiddleware(action);
     }));
 }
コード例 #2
0
 public static IXamarinHostBuilder UseNavigationMiddleware <TMiddleware>(this IXamarinHostBuilder builder) where TMiddleware : class
 {
     return(builder.ConfigureNavigation((ctx, sp, sb) =>
     {
         sb.UseMiddleware <TMiddleware>();
     }));
 }
コード例 #3
0
 /// <summary>
 /// Configures the host services with an insatnce of <see cref="IXamarinHostingPlatform"/>
 /// </summary>
 /// <typeparam name ="TPlatform">The type used to register <see cref="IXamarinHostingPlatform"/></typeparam>
 /// <param name="builder">The <see cref="IXamarinHostBuilder"/> to configure.</param>
 /// <param name="platform">The instance of <see cref="IXamarinHostingPlatform"/> to register.</param>
 /// <returns>The <see cref="IXamarinHostBuilder"/>.</returns>
 public static IXamarinHostBuilder UsePlatform <TPlatform>(this IXamarinHostBuilder builder, TPlatform platform) where TPlatform : IXamarinHostingPlatform
 {
     return(builder.ConfigureServices((context, services) =>
     {
         services.AddSingleton <IXamarinHostingPlatform>(platform);
     }));
 }
コード例 #4
0
 public static IXamarinHostBuilder UseNavigationMiddleware(this IXamarinHostBuilder builder, Func <PopModalDelegate, NavigationContext, Task> func)
 {
     return(builder.ConfigureNavigation((ctx, sp, sb) =>
     {
         sb.UseMiddleware(func);
     }));
 }
コード例 #5
0
 /// <summary>
 /// Configures the host services with an insatnce of <see cref="IXamarinApplication"/>
 /// </summary>
 /// <typeparam name ="TApp">The type used to register <see cref="IXamarinApplication"/></typeparam>
 /// <param name="builder">The <see cref="IXamarinHostBuilder"/> to configure.</param>
 /// <param name="app">The instance of <see cref="IXamarinApplication"/> to register.</param>
 /// <returns>The <see cref="IXamarinHostBuilder"/>.</returns>
 public static IXamarinHostBuilder UseApplication <TApp>(this IXamarinHostBuilder builder, TApp app) where TApp : class
 {
     return(builder.ConfigureServices((context, services) =>
     {
         XamarinApplicationDelegate @delegate = () => app;
         services.AddSingleton(@delegate);
     }));
 }
コード例 #6
0
        public static IXamarinHostBuilder UseNavigationRoot <TNavigationRoot>(this IXamarinHostBuilder builder, TNavigationRoot root) where TNavigationRoot : class
        {
            return(builder.ConfigureServices((context, services) =>
            {
                if (!typeof(INavigation).IsAssignableFrom(typeof(TNavigationRoot)) || !typeof(Application).IsAssignableFrom(typeof(TNavigationRoot)))
                {
                    throw new InvalidOperationException($"Navigation root must be of type {nameof(INavigation)} or {nameof(Application)}");
                }

                services.AddSingleton <XamarinNavigationRootDelegate>(sp => () => root);
            }));
        }
コード例 #7
0
        /// <summary>
        /// Configures the host services with an insatnce of <see cref="IXamarinApplication"/>
        /// </summary>
        /// <typeparam name ="TApp">The type used to register <see cref="IXamarinApplication"/>. Must either be of type Application or IXamarinApplication</typeparam>
        /// <param name="builder">The <see cref="IXamarinHostBuilder"/> to configure.</param>
        /// <returns>The <see cref="IXamarinHostBuilder"/>.</returns>
        public static IXamarinHostBuilder UseApplication <TApp>(this IXamarinHostBuilder builder) where TApp : class
        {
            return(builder.ConfigureServices((context, services) =>
            {
                var factory = new XamarinApplicationDelegateFactory();

                services.AddSingleton(sp =>
                {
                    factory.Init(sp);
                    return factory.Create <TApp>();
                });
            }));
        }
コード例 #8
0
 /// <summary>
 /// Configures the host services with a Startup class
 /// </summary>
 /// <param name="builder">The <see cref="IXamarinHostBuilder"/> to configure.</param>
 /// <param name="startupType">The class type to configure services with</param>
 /// <returns>The <see cref="IXamarinHostBuilder"/>.</returns>
 public static IXamarinHostBuilder UseStartup(this IXamarinHostBuilder builder, Type startupType)
 {
     return(builder
            .ConfigureServices((context, services) =>
     {
         if (typeof(IXamarinStartup).GetTypeInfo().IsAssignableFrom(startupType.GetTypeInfo()))
         {
             services.AddSingleton(typeof(IXamarinStartup), startupType);
         }
         else
         {
             services.AddSingleton(typeof(IXamarinStartup), sp =>
             {
                 var hostingEnvironment = sp.GetRequiredService <IXamarinHostEnvironment>();
                 return new XamarinStartup(StartupLoader.LoadMethods(sp, startupType, hostingEnvironment.EnvironmentName));
             });
         }
     }));
 }
コード例 #9
0
        /// <summary>
        /// Initializes <see cref="IConfiguration"/> with appsettings,json files.
        /// </summary>
        /// <param name="builder">The <see cref="IXamarinHostBuilder"/> to configure.</param>
        /// <param name="assembly">The assembly that contains the embedded appsettings.json files.</param>
        /// <returns>The <see cref="IXamarinHostBuilder"/>.</returns>
        public static IXamarinHostBuilder UseAppSettings(this IXamarinHostBuilder builder, Assembly assembly)
        {
            return(builder.ConfigureHostConfiguration(c =>
            {
                c.AddEmbeddedJsonFile(assembly, "appsettings.json");

                var environment = c.Build().GetValue <string>(XamarinHostDefaults.EnvironmentKey);

                if (!string.IsNullOrEmpty(environment))
                {
                    try
                    {
                        c.AddEmbeddedJsonFile(assembly, $"appsettings.{environment}.json");
                    }
                    catch (FileNotFoundException)
                    {
                        // At this point it just means an environment is supplied but no appsetting exists for it
                    }
                }
            }));
        }
コード例 #10
0
        /// <summary>
        /// Configures the host services with a Startup class
        /// </summary>
        /// <typeparam name ="TStartup">The type used to configure services</typeparam>
        /// <param name="hostBuilder">The <see cref="IXamarinHostBuilder"/> to configure.</param>
        /// <param name="startup">The instance of startup class to configure services with</param>
        /// <returns>The <see cref="IXamarinHostBuilder"/>.</returns>
        public static IXamarinHostBuilder UseStartup <TStartup>(this IXamarinHostBuilder hostBuilder, TStartup startup) where TStartup : class
        {
            var startupType = typeof(TStartup);

            return(hostBuilder
                   .ConfigureServices((context, services) =>
            {
                if (typeof(IXamarinStartup).GetTypeInfo().IsAssignableFrom(startupType.GetTypeInfo()))
                {
                    services.AddSingleton((IXamarinStartup)startup);
                }
                else
                {
                    services.AddSingleton <IXamarinStartup>(sp =>
                    {
                        var hostingEnvironment = sp.GetRequiredService <IXamarinHostEnvironment>();
                        return new XamarinStartup(StartupLoader.LoadMethods(startup, hostingEnvironment.EnvironmentName));
                    });
                }
            }));
        }
コード例 #11
0
 /// <summary>
 /// Configures the host services with an insatnce of <see cref="IXamarinHostingPlatform"/>
 /// </summary>
 /// <param name="builder">The <see cref="IXamarinHostBuilder"/> to configure.</param>
 /// <param name="app">The instance of <see cref="FormsApplicationDelegate"/> to register.</param>
 /// <returns>The <see cref="IXamarinHostBuilder"/>.</returns>
 public static IXamarinHostBuilder UsePlatform(this IXamarinHostBuilder builder, FormsApplicationDelegate app)
 {
     return(builder.UsePlatform(new IOSHostingPlatform(app)));
 }
コード例 #12
0
 /// <summary>
 /// Initializes <see cref="IConfiguration"/> with appsettings,json files.
 /// </summary>
 /// <typeparam name ="TAssemblyClass">The type in the assembly that contains the embedded appsettings.json files</typeparam>
 /// <param name="builder">The <see cref="IXamarinHostBuilder"/> to configure.</param>
 /// <returns>The <see cref="IXamarinHostBuilder"/>.</returns>
 public static IXamarinHostBuilder UseAppSettings <TAssemblyClass>(this IXamarinHostBuilder builder)
 {
     return(builder.UseAppSettings(typeof(TAssemblyClass).Assembly));
 }
コード例 #13
0
 /// <summary>
 /// Configures the host services with a Startup class
 /// </summary>
 /// <typeparam name ="TStartup">The type used to configure services</typeparam>
 /// <param name="hostBuilder">The <see cref="IXamarinHostBuilder"/> to configure.</param>
 /// <returns>The <see cref="IXamarinHostBuilder"/>.</returns>
 public static IXamarinHostBuilder UseStartup <TStartup>(this IXamarinHostBuilder hostBuilder) where TStartup : class, new()
 {
     return(hostBuilder.UseStartup(new TStartup()));
 }
コード例 #14
0
 /// <summary>
 /// Configures the host services with an insatnce of <see cref="IXamarinHostingPlatform"/>
 /// </summary>
 /// <param name="builder">The <see cref="IXamarinHostBuilder"/> to configure.</param>
 /// <param name="app">The instance of <see cref="FormsAppCompatActivity"/> to register.</param>
 /// <returns>The <see cref="IXamarinHostBuilder"/>.</returns>
 public static IXamarinHostBuilder UsePlatform(this IXamarinHostBuilder builder, FormsAppCompatActivity app)
 {
     return(builder.UsePlatform(new AndroidHostingPlatform(app)));
 }
コード例 #15
0
        public XamarinHostSpecification()
        {
            _xamarinHostBuilder = new XamarinHostBuilder();

            Device.PlatformServices = new MockPlatformServices();
        }