コード例 #1
0
ファイル: EcsManager.cs プロジェクト: TheFuseGamer/SampSharp
 private void Configure(IServiceCollection services)
 {
     _startup.Configure(
         services.AddSingleton <IEventService, EventService>()
         .AddSingleton <ISystemRegistry, SystemRegistry>()
         .AddSingleton <IEntityManager, EntityManager>()
         .AddSingleton <IServerService, ServerService>()
         .AddSingleton <IWorldService, WorldService>()
         .AddSingleton <IVehicleInfoService, VehicleInfoService>()
         .AddSingleton <IPlayerCommandService, PlayerCommandService>()
         .AddSingleton <IRconCommandService, RconCommandService>()
         .AddTransient <IDialogService, DialogService>()
         .AddTransient(typeof(INativeProxy <>), typeof(NativeProxy <>))
         .AddSystem <DialogSystem>()
         );
 }
コード例 #2
0
        public IHost Build()
        {
            foreach (var keyValuePair in Properties.Select(x => new KeyValuePair <object, object>(x.Key, x.Value)))
            {
                _frontSideBuilder.Properties.Add(keyValuePair);
                _backSideBuilder.Properties.Add(keyValuePair);
            }

            _startup = _backSideBuilder
                       .Build()
                       .Services
                       .GetService <IStartup>();

            if (_startup != null)
            {
                _frontSideBuilder
                .ConfigureServices(services => _startup.ConfigureServices(services));

                _frontSideBuilder
                .ConfigureHostConfiguration(builder => _startup.Configure(_frontSideBuilder));
            }

            return
                (_frontSideBuilder
                 .Build());
        }
コード例 #3
0
        public static void AddEmbedded(
            this IApplicationBuilder appBuilder,
            PathString path,
            string startupTypeName,
            Func <HttpMessageHandler> messageHandlerFactory = null)
        {
            IConfiguration config = appBuilder.ApplicationServices
                                    .GetRequiredService <IConfiguration>();

            IHostingEnvironment environment = appBuilder.ApplicationServices
                                              .GetRequiredService <IHostingEnvironment>();

            ILoggerFactory loggerFactory = appBuilder.ApplicationServices
                                           .GetRequiredService <ILoggerFactory>();

            IStartup startup = CreateStartupInstance(
                startupTypeName,
                config,
                environment,
                loggerFactory,
                messageHandlerFactory);

            appBuilder.MapStartup(
                path,
                environment,
                config,
                (services) =>
            {
                startup.ConfigureServices(services);
            },
                (app) =>
            {
                startup.Configure(app);
            });
        }
コード例 #4
0
ファイル: ConsoleHost.cs プロジェクト: micdenny/CServi
        public void Configure()
        {
            var env = new HostingEnvironment();

            var services = new ServiceCollection();

            services.AddSingleton <IHostingEnvironment, HostingEnvironment>();
            services.AddSingleton <IApplicationLifetime, ApplicationLifetime>();
            services.AddSingleton <IApplicationBuilder, ApplicationBuilder>();
            services.AddLogging();

            IStartup startup = FindAndConstructStartupViaReflection(env);

            startup.ConfigureServices(services);

            _serviceProvider = services.BuildServiceProvider();

            _logger = _serviceProvider.GetRequiredService <ILogger <ConsoleHost> >();

            _applicationBuilder  = _serviceProvider.GetRequiredService <IApplicationBuilder>();
            _applicationLifetime = _serviceProvider.GetRequiredService <IApplicationLifetime>() as ApplicationLifetime;
            var loggerFactory = _serviceProvider.GetRequiredService <ILoggerFactory>();

            startup.Configure(_applicationBuilder, env, loggerFactory, _applicationLifetime);
        }
コード例 #5
0
        private HostingApplication BuildApplication()
        {
            _startup.Configure(_applicationBuilder);
            //var configure = _hostingOptions.ConfigureApp ?? throw new InvalidOperationException($"No application configured. Please specify an application via HostBuilder.Configure in the host configuration.");
            //configure(_applicationBuilder);
            _applicationBuilder.Use(next => new RouterMiddleware(next, _routeBuilder.Build()).Invoke);

            RequestDelegate application = _applicationBuilder.Build();

            var contextFactory   = _applicationServices.GetRequiredService <IOwinContextFactory>();
            var diagnosticSource = _applicationServices.GetRequiredService <DiagnosticListener>();

            return(new HostingApplication(application, contextFactory, diagnosticSource));
        }
コード例 #6
0
        private void BuildApplication()
        {
            //注册所有的依赖和服务
            EnsureApplicationServices();
            EnsureServer();

            //_applicationServices.GetRequiredService<IServiceActorContainer>();
            var appbuilder = _applicationServices.GetRequiredService <IAppBuilder>();
            var env        = _applicationServices.GetRequiredService <IHostingEnvironment>();

            appbuilder.ServiceProvider = this._applicationServices;

            _startup.Configure(appbuilder, env);

            Environment.SetServiceProvider(this._applicationServices);
            _initialized = true;
        }
コード例 #7
0
        public static IWebHostBuilder UseStartup(this IWebHostBuilder builder, Type startupType)
        {
            var typeInfo     = startupType.GetTypeInfo();
            var constructors = typeInfo.GetConstructors()
                               .Where(x => x.IsPublic)
                               .OrderBy(x => x.GetParameters().Length);

            IStartup startup = null;

            foreach (var constructor in constructors)
            {
                var parameters = constructor.GetParameters();
                var objParams  = new object[parameters.Length];
                int i          = 0;
                for (i = 0; i < parameters.Length; i++)
                {
                    if (DefaultParamterValue.TryGetDefaultValue(parameters[i], out var value))
                    {
                        objParams[i] = value;
                        var x = new ConfigurationBuilder();
                    }
                    else
                    {
                        break;
                    }
                }

                if (i < parameters.Length)
                {
                    continue;
                }

                startup = (IStartup)constructor.Invoke(objParams);
                break;
            }

            if (startup == null)
            {
                throw new InvalidOperationException("操作失败,无法构造出Startup类");
            }

            return(builder.Configure(
                       services => startup.ConfigureServices(services),
                       app => startup.Configure(app)));
        }
コード例 #8
0
ファイル: PluginManager.cs プロジェクト: atlocke/MiNET_Test
        internal void ExecuteStartup(MiNetServer server)
        {
            foreach (object plugin in _plugins)
            {
                IStartup startupClass = plugin as IStartup;
                if (startupClass == null)
                {
                    continue;
                }

                try
                {
                    startupClass.Configure(server);
                }
                catch (Exception ex)
                {
                    Log.Warn("Execute Startup class failed", ex);
                }
            }
        }
コード例 #9
0
 public void Configure(IApplicationBuilder app)
 {
     _startupImplementation.Configure(app);
 }
コード例 #10
0
        public static IAppHostBuilder ConfigureUsing(this IAppHostBuilder appHostBuilder, IStartup startup)
        {
            startup.Configure(appHostBuilder);

            return(appHostBuilder);
        }
コード例 #11
0
 public void Configure(IApplicationBuilder app, IStartup startup)
 {
     startup.Configure(app);
 }
コード例 #12
0
        /// <summary>
        /// Creates a web server that will bind to local addresses to any available port.
        /// </summary>
        /// <param name="isPrivate">
        /// Whether or not the host should bind to the loopback adapter, or a public interface.
        /// </param>
        /// <param name="isV6">
        /// Whether or not this server should be bound to a v6 address. We have yet to determine if
        /// we can even grab some internal of kestrel that will allow us to manipulate the listener
        /// socket endpoint to force it into dual mode, so we use this option instead and generate
        /// two hosts.
        /// </param>
        /// <param name="boundHttpEndpoint">
        /// The endpoint that the HTTP host was bound to.
        /// </param>
        /// <param name="startupInsance">
        /// The startup instance to use for the server.
        /// </param>
        /// <returns>
        /// An IWebHost that will transparently proxy all requests.
        /// </returns>
        /// <exception cref="NullReferenceException">
        /// In the event that the internal kestrel engine doesn't properly initialize, this method
        /// will throw.
        /// </exception>
        private IWebHost CreateHost <T>(bool isPrivate, bool isV6, out IPEndPoint boundHttpEndpoint, IStartup startupInsance) where T : class
        {
            WebHostBuilder ipWebhostBuilder = new WebHostBuilder();

            ListenOptions httpListenOptions = null;

            ipWebhostBuilder.UseSockets(opts =>
            {
                //opts.IOQueueCount = 0;
                opts.IOQueueCount = byte.MaxValue;
            });

            // Use Kestrel server.
            ipWebhostBuilder.UseKestrel(opts =>
            {
                opts.Limits.MaxRequestBodySize               = null;
                opts.Limits.MaxConcurrentConnections         = null;
                opts.Limits.MaxConcurrentUpgradedConnections = null;
                opts.Limits.MaxRequestLineSize               = ushort.MaxValue;
                opts.Limits.MaxResponseBufferSize            = ushort.MaxValue * byte.MaxValue;
                opts.Limits.MinResponseDataRate              = null; //new MinDataRate(ushort.MaxValue * 10, TimeSpan.FromSeconds(30));
                opts.AddServerHeader           = false;
                opts.ApplicationSchedulingMode = Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.SchedulingMode.Inline;
                opts.AllowSynchronousIO        = true;

                // Listen for HTTPS connections. Keep a reference to the options object so we can get
                // the chosen port number after we call start.
                opts.Listen(isV6 ? IPAddress.IPv6Any : IPAddress.Any, 0, listenOpts =>
                {
                    // Plug in our TLS connection adapter. This adapter will handle SNI parsing and
                    // certificate spoofing based on the SNI value.
                    listenOpts.ConnectionAdapters.Add(_tlsConnAdapter);

                    // Who doesn't love to kick that old Nagle to the curb?
                    listenOpts.NoDelay = true;

                    // HTTP 2 got cut last minute from 2.1 and MS speculates that it may take several
                    // releases to get it properly included.
                    // https://github.com/aspnet/Docs/issues/5242#issuecomment-380863456
                    listenOpts.Protocols = HttpProtocols.Http1AndHttp2;

                    httpListenOptions = listenOpts;
                });
            });

            // Add compression for responses.
            ipWebhostBuilder.ConfigureServices(serviceOpts =>
            {
                startupInsance.ConfigureServices(serviceOpts);
                //serviceOpts.AddResponseCompression();

                // Add existing startup instance! This is how/where we handle connections.
                serviceOpts.AddSingleton <IStartup>(startupInsance);
            });

            ipWebhostBuilder.Configure(cfgApp =>
            {
                startupInsance.Configure(cfgApp);
                //cfgApp.UseResponseCompression();
            });

            // Build host. You needed this comment.
            var vHost = ipWebhostBuilder.Build();

            // Start the host. You definitely needed this. It's not until we start the host that the
            // listener endpoints will be resolved. We need that info so we know where our proxy
            // server is running, so we can divert packets to it.
            vHost.Start();

            // Since this is post vHost.Start(), we can now grab the EP of the connection.
            if (httpListenOptions != null)
            {
                boundHttpEndpoint = httpListenOptions.IPEndPoint;
            }
            else
            {
                throw new NullReferenceException("httpListenOptions is expected to be non-null!");
            }

            return(vHost);
        }