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); }
public static IGameHostBuilder UseTestServer(this IGameHostBuilder builder) { return(builder.ConfigureServices(services => { services.AddSingleton <IServer, TestServer>(); })); }
/// <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>(); })); }
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 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 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 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> /// 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 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); }
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> /// 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); });
/// <summary> /// Adds a delegate for configuring the provided <see cref="ILoggingBuilder"/>. This may be called multiple times. /// </summary> /// <param name="hostBuilder">The <see cref="IGameHostBuilder" /> to configure.</param> /// <param name="configureLogging">The delegate that configures the <see cref="ILoggingBuilder"/>.</param> /// <returns>The <see cref="IGameHostBuilder"/>.</returns> public static IGameHostBuilder ConfigureLogging(this IGameHostBuilder hostBuilder, Action <ILoggingBuilder> configureLogging) => hostBuilder.ConfigureServices(collection => collection.AddLogging(configureLogging));
/// <summary> /// Configures Standard options but does not register an IClient. See <see cref="UseStandard(IGameHostBuilder)"/>. /// </summary> /// <param name="hostBuilder"> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder to configure. /// </param> /// <param name="options"> /// A callback to configure Standard options. /// </param> /// <returns> /// The Contoso.GameNetCore.Hosting.IGameHostBuilder. /// </returns> public static IGameHostBuilder ConfigureStandard(this IGameHostBuilder hostBuilder, Action <StandardClientOptions> options) => hostBuilder.ConfigureServices(services => { services.Configure(options); });
/// <summary> /// Adds a delegate for configuring the provided <see cref="LoggerFactory"/>. This may be called multiple times. /// </summary> /// <param name="hostBuilder">The <see cref="IGameHostBuilder" /> to configure.</param> /// <param name="configureLogging">The delegate that configures the <see cref="LoggerFactory"/>.</param> /// <returns>The <see cref="IGameHostBuilder"/>.</returns> public static IGameHostBuilder ConfigureLogging(this IGameHostBuilder hostBuilder, Action <GameHostBuilderContext, ILoggingBuilder> configureLogging) => hostBuilder.ConfigureServices((context, collection) => collection.AddLogging(builder => configureLogging(context, builder)));