public static IGameHostBuilder UseTestServer(this IGameHostBuilder builder) { return(builder.ConfigureServices(services => { services.AddSingleton <IServer, TestServer>(); })); }
internal static void ConfigureGameDefaults(IGameHostBuilder builder) { builder //.UseKestrel((builderContext, options) => //{ // options.Configure(builderContext.Configuration.GetSection("Kestrel")); //}) .ConfigureServices((hostingContext, services) => { // Fallback services.PostConfigure <HostFilteringOptions>(options => { if (options.AllowedHosts == null || options.AllowedHosts.Count == 0) { // "AllowedHosts": "localhost;127.0.0.1;[::1]" var hosts = hostingContext.Configuration["AllowedHosts"]?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); // Fall back to "*" to disable. options.AllowedHosts = hosts?.Length > 0 ? hosts : new[] { "*" }; } }); // Change notification services.AddSingleton <IOptionsChangeTokenSource <HostFilteringOptions> >( new ConfigurationChangeTokenSource <HostFilteringOptions>(hostingContext.Configuration)); services.AddTransient <IStartupFilter, HostFilteringStartupFilter>(); services.AddRouting(); }); }
/// <summary> /// Specify Sockets as the transport to be used by Kestrel. /// </summary> /// <param name="hostBuilder"> /// The Microsoft.AspNetCore.Hosting.IGameHostBuilder to configure. /// </param> /// <returns> /// The Microsoft.AspNetCore.Hosting.IGameHostBuilder. /// </returns> public static IGameHostBuilder UseSockets(this IGameHostBuilder hostBuilder) { return(hostBuilder.ConfigureServices(services => { services.AddSingleton <ITransportFactory, SocketTransportFactory>(); })); }
public static IGameHostBuilder ConfigureTestServices(this IGameHostBuilder gameHostBuilder, Action <IServiceCollection> servicesConfiguration) { if (gameHostBuilder == null) { throw new ArgumentNullException(nameof(gameHostBuilder)); } if (servicesConfiguration == null) { throw new ArgumentNullException(nameof(servicesConfiguration)); } if (gameHostBuilder.GetType().Name.Equals("GenericGameHostBuilder")) { // Generic host doesn't need to do anything special here since there's only one container. gameHostBuilder.ConfigureServices(servicesConfiguration); } else { gameHostBuilder.ConfigureServices( s => s.AddSingleton <IStartupConfigureServicesFilter>( new ConfigureTestServicesStartupConfigureServicesFilter(servicesConfiguration))); } return(gameHostBuilder); }
/// <summary> /// Specify Sockets as the transport to be used by Kestrel. /// </summary> /// <param name="hostBuilder"> /// The Microsoft.AspNetCore.Hosting.IGameHostBuilder to configure. /// </param> /// <param name="configureOptions"> /// A callback to configure Libuv options. /// </param> /// <returns> /// The Microsoft.AspNetCore.Hosting.IGameHostBuilder. /// </returns> public static IGameHostBuilder UseSockets(this IGameHostBuilder hostBuilder, Action <SocketTransportOptions> configureOptions) { return(hostBuilder.UseSockets().ConfigureServices(services => { services.Configure(configureOptions); })); }
public static IGameHostBuilder UseSolutionRelativeContentRoot( this IGameHostBuilder builder, string solutionRelativePath, string applicationBasePath, string solutionName = "*.sln") { if (solutionRelativePath == null) { throw new ArgumentNullException(nameof(solutionRelativePath)); } if (applicationBasePath == null) { throw new ArgumentNullException(nameof(applicationBasePath)); } var directoryInfo = new DirectoryInfo(applicationBasePath); do { var solutionPath = Directory.EnumerateFiles(directoryInfo.FullName, solutionName).FirstOrDefault(); if (solutionPath != null) { builder.UseContentRoot(Path.GetFullPath(Path.Combine(directoryInfo.FullName, solutionRelativePath))); return(builder); } directoryInfo = directoryInfo.Parent; }while (directoryInfo.Parent != null); throw new InvalidOperationException($"Solution root could not be located using application root {applicationBasePath}."); }
public static IGameHostBuilder UseSolutionRelativeContentRoot( this IGameHostBuilder builder, string solutionRelativePath, string solutionName = "*.sln") { return(builder.UseSolutionRelativeContentRoot(solutionRelativePath, AppContext.BaseDirectory, solutionName)); }
/// <summary> /// Start the game host and listen on the specified urls. /// </summary> /// <param name="hostBuilder">The <see cref="IGameHostBuilder"/> to start.</param> /// <param name="urls">The urls the hosted application will listen on.</param> /// <returns>The <see cref="IGameHostBuilder"/>.</returns> public static IGameHost Start(this IGameHostBuilder hostBuilder, params string[] urls) { var host = hostBuilder.UseUrls(urls).Build(); host.StartAsync(CancellationToken.None).GetAwaiter().GetResult(); return(host); }
/// <summary> /// Specify the startup type to be used by the game host. /// </summary> /// <param name="hostBuilder">The <see cref="IGameHostBuilder"/> to configure.</param> /// <param name="startupType">The <see cref="Type"/> to be used.</param> /// <returns>The <see cref="IGameHostBuilder"/>.</returns> public static IGameHostBuilder UseStartup(this IGameHostBuilder hostBuilder, Type startupType) { var startupAssemblyName = startupType.GetTypeInfo().Assembly.GetName().Name; hostBuilder.UseSetting(GameHostDefaults.ApplicationKey, startupAssemblyName); // Light up the GenericGameHostBuilder implementation if (hostBuilder is ISupportsStartup supportsStartup) { return(supportsStartup.UseStartup(startupType)); } return(hostBuilder .ConfigureServices(services => { if (typeof(IStartup).GetTypeInfo().IsAssignableFrom(startupType.GetTypeInfo())) { services.AddSingleton(typeof(IStartup), startupType); } else { services.AddSingleton(typeof(IStartup), sp => { var hostingEnvironment = sp.GetRequiredService <IHostEnvironment>(); return new ConventionBasedStartup(StartupLoader.LoadMethods(sp, startupType, hostingEnvironment.EnvironmentName)); }); } })); }
/// <summary> /// Specify the urls the game host will listen on. /// </summary> /// <param name="hostBuilder">The <see cref="IGameHostBuilder"/> to configure.</param> /// <param name="urls">The urls the hosted application will listen on.</param> /// <returns>The <see cref="IGameHostBuilder"/>.</returns> public static IGameHostBuilder UseUrls(this IGameHostBuilder hostBuilder, params string[] urls) { if (urls == null) { throw new ArgumentNullException(nameof(urls)); } return(hostBuilder.UseSetting(GameHostDefaults.ServerUrlsKey, string.Join(ServerUrlsSeparator, urls))); }
/// <summary> /// Specify Simple as the server to be used by the game host. /// </summary> /// <param name="hostBuilder"> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder to configure. /// </param> /// <returns> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder. /// </returns> public static IGameHostBuilder UseSimple(this IGameHostBuilder hostBuilder) { return(hostBuilder.ConfigureServices(services => { services.AddTransient <IConfigureOptions <SimpleServerOptions>, SimpleServerOptionsSetup>(); services.AddSingleton <IServer, SimpleServer>(); })); }
/// <summary> /// Specify the content root directory to be used by the game host. /// </summary> /// <param name="hostBuilder">The <see cref="IGameHostBuilder"/> to configure.</param> /// <param name="contentRoot">Path to root directory of the application.</param> /// <returns>The <see cref="IGameHostBuilder"/>.</returns> public static IGameHostBuilder UseContentRoot(this IGameHostBuilder hostBuilder, string contentRoot) { if (contentRoot == null) { throw new ArgumentNullException(nameof(contentRoot)); } return(hostBuilder.UseSetting(GameHostDefaults.ContentRootKey, contentRoot)); }
/// <summary> /// Specify the environment to be used by the game host. /// </summary> /// <param name="hostBuilder">The <see cref="IGameHostBuilder"/> to configure.</param> /// <param name="environment">The environment to host the application in.</param> /// <returns>The <see cref="IGameHostBuilder"/>.</returns> public static IGameHostBuilder UseEnvironment(this IGameHostBuilder hostBuilder, string environment) { if (environment == null) { throw new ArgumentNullException(nameof(environment)); } return(hostBuilder.UseSetting(GameHostDefaults.EnvironmentKey, environment)); }
/// <summary> /// Specify the server to be used by the game host. /// </summary> /// <param name="hostBuilder">The <see cref="IGameHostBuilder"/> to configure.</param> /// <param name="server">The <see cref="IServer"/> to be used.</param> /// <returns>The <see cref="IGameHostBuilder"/>.</returns> public static IGameHostBuilder UseServer(this IGameHostBuilder hostBuilder, IServer server) { if (server == null) { throw new ArgumentNullException(nameof(server)); } return(hostBuilder.ConfigureServices(services => services.AddSingleton(server))); }
/// <summary> /// Use the given configuration settings on the game host. /// </summary> /// <param name="hostBuilder">The <see cref="IGameHostBuilder"/> to configure.</param> /// <param name="configuration">The <see cref="IConfiguration"/> containing settings to be used.</param> /// <returns>The <see cref="IGameHostBuilder"/>.</returns> public static IGameHostBuilder UseConfiguration(this IGameHostBuilder hostBuilder, IConfiguration configuration) { foreach (var setting in configuration.AsEnumerable(makePathsRelative: true)) { hostBuilder.UseSetting(setting.Key, setting.Value); } return(hostBuilder); }
public static IGameHostBuilder ConfigurePlatform(this IGameHostBuilder hostBuilder) { hostBuilder .ConfigureCoreApplication() .ConfigurePlatformGraphics(); return(hostBuilder); }
/// <summary> /// Specify Standard as the client to be used by the game host. /// </summary> /// <param name="hostBuilder"> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder to configure. /// </param> /// <returns> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder. /// </returns> public static IGameHostBuilder UseStandard(this IGameHostBuilder hostBuilder) { return(hostBuilder.ConfigureServices(services => { services.AddTransient <IConfigureOptions <StandardClientOptions>, StandardClientOptionsSetup>(); services.AddSingleton <IClient, StandardClient>(); })); }
/// <summary> /// Specify the assembly containing the startup type to be used by the game host. /// </summary> /// <param name="hostBuilder">The <see cref="IGameHostBuilder"/> to configure.</param> /// <param name="startupAssemblyName">The name of the assembly containing the startup type.</param> /// <returns>The <see cref="IGameHostBuilder"/>.</returns> public static IGameHostBuilder UseStartup(this IGameHostBuilder hostBuilder, string startupAssemblyName) { if (startupAssemblyName == null) { throw new ArgumentNullException(nameof(startupAssemblyName)); } return(hostBuilder .UseSetting(GameHostDefaults.ApplicationKey, startupAssemblyName) .UseSetting(GameHostDefaults.StartupAssemblyKey, startupAssemblyName)); }
public static void ConfigureGameFrameworkDefaults(IGameHostBuilder builder) { builder.ConfigureAppConfiguration((context, cb) => { if (context.HostingEnvironment.EnvironmentName == "Development") { } }) .ConfigureFramework(); }
/// <summary> /// Specify Kestrel as the server to be used by the game host. /// </summary> /// <param name="hostBuilder"> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder to configure. /// </param> /// <returns> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder. /// </returns> public static IGameHostBuilder UseKestrel(this IGameHostBuilder hostBuilder) { return(hostBuilder.ConfigureServices(services => { // Don't override an already-configured transport services.TryAddSingleton <ITransportFactory, SocketTransportFactory>(); services.AddTransient <IConfigureOptions <KestrelServerOptions>, KestrelServerOptionsSetup>(); services.AddSingleton <IServer, KestrelServer>(); })); }
public static IGameHostBuilder ConfigurePlatformGraphics(this IGameHostBuilder hostBuilder) { hostBuilder.ConfigureServices(services => { services.AddSingleton <IGraphicsDeviceAdapter, CanvasDeviceAdapter>(); services.AddSingleton <ISwapChain, CanvasSwapChainAdapter>(); services.AddSingleton <ITextureResourceLoader, CanvasBitmapResourceLoader>(); }); return(hostBuilder); }
/// <summary> /// For use with IGameHostBuilder. /// </summary> /// <param name="builder"></param> /// <param name="featureCollection"></param> public TestServer(IGameHostBuilder builder, IFeatureCollection featureCollection) : this(featureCollection) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } var host = builder.UseServer(this).Build(); host.StartAsync().GetAwaiter().GetResult(); _hostInstance = host; }
public static IGameHostBuilder ConfigureFramework(this IGameHostBuilder hostBuilder) { hostBuilder.ConfigureServices(services => { services.AddSingleton <IResourceManager, ResourceManager>(); services.AddSingleton <IGraphicsDevice, GraphicsDevice>(); services.AddSingleton <IGameWindow, GameWindow>(); services.AddSingleton <IKeyboard, Keyboard>(); services.AddSingleton <IInputManager, InputManager>(); }); return(hostBuilder); }
/// <summary> /// Configures Kestrel options but does not register an IServer. See <see cref="UseKestrel(IGameHostBuilder)"/>. /// </summary> /// <param name="hostBuilder"> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder to configure. /// </param> /// <param name="configureOptions">A callback to configure Kestrel options.</param> /// <returns> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder. /// </returns> public static IGameHostBuilder ConfigureKestrel(this IGameHostBuilder hostBuilder, Action <GameHostBuilderContext, KestrelServerOptions> configureOptions) { if (configureOptions == null) { throw new ArgumentNullException(nameof(configureOptions)); } return(hostBuilder.ConfigureServices((context, services) => { services.Configure <KestrelServerOptions>(options => { configureOptions(context, options); }); })); }
public static IGameHostBuilder ConfigureCoreApplication(this IGameHostBuilder hostBuilder) { hostBuilder.ConfigureServices(services => { services.AddSingleton <IGameFrameworkView, GameFrameworkView>(); services.AddSingleton <ICoreApplicationContext, CoreApplicationContext>(); services.AddSingleton <IPlatformWindow, CoreWindowAdapter>(); services.AddSingleton <IKeyboardInputSource, CoreWindowKeyboardInputSource>(); services.AddHostedService <CoreApplicationHostedService>(); }); return(hostBuilder); }
/// <summary> /// Configures the default service provider /// </summary> /// <param name="hostBuilder">The <see cref="IGameHostBuilder"/> to configure.</param> /// <param name="configure">A callback used to configure the <see cref="ServiceProviderOptions"/> for the default <see cref="IServiceProvider"/>.</param> /// <returns>The <see cref="IGameHostBuilder"/>.</returns> public static IGameHostBuilder UseDefaultServiceProvider(this IGameHostBuilder hostBuilder, Action <GameHostBuilderContext, ServiceProviderOptions> configure) { // Light up the GenericGameHostBuilder implementation if (hostBuilder is ISupportsUseDefaultServiceProvider supportsDefaultServiceProvider) { return(supportsDefaultServiceProvider.UseDefaultServiceProvider(configure)); } return(hostBuilder.ConfigureServices((context, services) => { var options = new ServiceProviderOptions(); configure(context, options); services.Replace(ServiceDescriptor.Singleton <IServiceProviderFactory <IServiceCollection> >(new DefaultServiceProviderFactory(options))); })); }
public static IGameHostBuilder ConfigureTestContainer <TContainer>(this IGameHostBuilder gameHostBuilder, Action <TContainer> servicesConfiguration) { if (gameHostBuilder == null) { throw new ArgumentNullException(nameof(gameHostBuilder)); } if (servicesConfiguration == null) { throw new ArgumentNullException(nameof(servicesConfiguration)); } gameHostBuilder.ConfigureServices( s => s.AddSingleton <IStartupConfigureContainerFilter <TContainer> >( new ConfigureTestServicesStartupConfigureContainerFilter <TContainer>(servicesConfiguration))); return(gameHostBuilder); }
static IGameHostBuilder Configure(this IGameHostBuilder hostBuilder, Action <GameHostBuilderContext, IApplicationBuilder> configureApp, string startupAssemblyName) { if (configureApp == null) { throw new ArgumentNullException(nameof(configureApp)); } hostBuilder.UseSetting(GameHostDefaults.ApplicationKey, startupAssemblyName); // Light up the ISupportsStartup implementation if (hostBuilder is ISupportsStartup supportsStartup) { return(supportsStartup.Configure(configureApp)); } return(hostBuilder.ConfigureServices((context, services) => { services.AddSingleton <IStartup>(sp => new DelegateStartup(sp.GetRequiredService <IServiceProviderFactory <IServiceCollection> >(), app => configureApp(context, app))); })); }
/// <summary> /// Specify Kestrel as the server to be used by the game host. /// </summary> /// <param name="hostBuilder"> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder to configure. /// </param> /// <param name="configureOptions">A callback to configure Kestrel options.</param> /// <returns> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder. /// </returns> public static IGameHostBuilder UseKestrel(this IGameHostBuilder hostBuilder, Action <GameHostBuilderContext, KestrelServerOptions> configureOptions) => hostBuilder.UseKestrel().ConfigureKestrel(configureOptions);
/// <summary> /// Configures Kestrel options but does not register an IServer. See <see cref="UseKestrel(IGameHostBuilder)"/>. /// </summary> /// <param name="hostBuilder"> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder to configure. /// </param> /// <param name="options"> /// A callback to configure Kestrel options. /// </param> /// <returns> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder. /// </returns> public static IGameHostBuilder ConfigureKestrel(this IGameHostBuilder hostBuilder, Action <KestrelServerOptions> options) => hostBuilder.ConfigureServices(services => { services.Configure(options); });