Esempio n. 1
0
        public static void Main(string[] args)
        {
            // Simple (and probably unreliable) IIS detection mechanism
            var model = Environment.GetEnvironmentVariable("ASPNETCORE_HOSTINGSTARTUPASSEMBLIES") == "Microsoft.AspNetCore.Server.IISIntegration" ? "IIS" : null;

            // The hosting model can be explicitly configured with the SERVER_HOSTING_MODEL environment variable.
            // See https://www.andrecarlucci.com/en/setting-environment-variables-for-asp-net-core-when-publishing-on-iis/ for
            // setting the variable in IIS.
            model = Environment.GetEnvironmentVariable("SERVER_HOSTING_MODEL") ?? model;
            // Command line arguments have higher precedence than environment variables
            model = args.FirstOrDefault(arg => arg.StartsWith("--use"))?.Substring(5) ?? model;

            var hostConfiguration = new AspNetCoreHostConfiguration(args)
                                    .UseStartup <Startup>()
                                    .UseWebHostBuilder(CreateWebHostBuilder)
                                    .BlockOnStart();

            switch (model)
            {
            case "Kestrel":
                hostConfiguration.UseKestrel();
                break;

            case "HttpSys":
                hostConfiguration.UseHttpSys();
                break;

            case "IIS":
                hostConfiguration.UseIIS();
                break;

            case "IISExpress":
                // Yes, _this_ is actually a "thing"...
                // The netstandard2.0 version of ASP.NET Core 2.2 works quite different when it comes to IISExpress integration
                // than its .NET Core counterpart.
                // * In a .NET 4.8 project, you MUST to UseKestrel when running in IISExpress
                // * In a .NET Core project (tested in 2.2 and 3.1), you MUST to UseIIS when running in IISExpress
                //
                // ... This just makes my brain hurt.
                if (IsDotNetCoreRuntime())
                {
                    hostConfiguration.UseIIS();
                }
                else
                {
                    hostConfiguration.UseKestrel();
                }
                break;

            default:
                throw new ArgumentException($"Unknown hosting model '{model}'");
            }

            var host = new NinjectSelfHostBootstrapper(CreateKernel, hostConfiguration);

            host.Start();
        }
Esempio n. 2
0
        public void CanReplaceDefaultControllerActivator()
        {
            var collection = new ServiceCollection();

            collection.Add(new ServiceDescriptor(typeof(IControllerActivator), new Mock <IControllerActivator>().Object));
            var config = new AspNetCoreHostConfiguration();

            config.UseCustomControllerActivator(typeof(CustomControllerActivator));
            var kernel = CreateKernel(collection, config);

            kernel.Get <IControllerActivator>().Should().NotBeNull().And.BeOfType(typeof(CustomControllerActivator));
        }
        protected IKernel CreateKernel(IServiceCollection collection, AspNetCoreHostConfiguration configuration = null)
        {
            var kernel = new StandardKernel(new NinjectSettings()
            {
                LoadExtensions = false
            });

            kernel.Load(typeof(AspNetCoreApplicationPlugin).Assembly);
            kernel.Bind <IServiceProvider>().ToConstant(new NinjectServiceProvider(kernel));
            kernel.Bind <AspNetCoreHostConfiguration>().ToConstant(configuration ?? new AspNetCoreHostConfiguration());
            kernel.Populate(collection);
            return(kernel);
        }
        public static void Main(string[] args)
        {
            // The hosting model can be explicitly configured with the SERVER_HOSTING_MODEL environment variable.
            // See https://www.andrecarlucci.com/en/setting-environment-variables-for-asp-net-core-when-publishing-on-iis/ for
            // setting the variable in IIS.
            var model = Environment.GetEnvironmentVariable("SERVER_HOSTING_MODEL");

            // Command line arguments have higher precedence than environment variables
            model = args.FirstOrDefault(arg => arg.StartsWith("--use"))?.Substring(5) ?? model;

            var hostConfiguration = new AspNetCoreHostConfiguration(args)
                                    .UseStartup <Startup>()
                                    .UseWebHostBuilder(CreateWebHostBuilder)
                                    .BlockOnStart();

            switch (model)
            {
            case "Kestrel":
                hostConfiguration.UseKestrel();
                break;

            case "HttpSys":
                hostConfiguration.UseHttpSys();
                break;

            case "IIS":
            case "IISExpress":
                hostConfiguration.UseIIS();
                break;

            default:
                throw new ArgumentException($"Unknown hosting model '{model}'");
            }

            var host = new NinjectSelfHostBootstrapper(CreateKernel, hostConfiguration);

            host.Start();
        }
Esempio n. 5
0
 public FixServicesForPublicatonAdapter(AspNetCoreHostConfiguration configuration)
 {
     _configuration = configuration;
 }