Ejemplo 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();
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     When implemented in a derived class, executes when a Start command
        ///     is sent to the service by the Service Control Manager (SCM) or when
        ///     the operating system starts (for a service that starts
        ///     automatically). Specifies actions to take when the service starts.
        /// </summary>
        /// <param name="args">Data passed by the start command.</param>
        protected override void OnStart(string[] args)
        {
            var serviceComfiguration =
                NinjectWcfConfiguration.Create <UppyDataManagerService, NinjectServiceSelfHostFactory>();

            selfHost = new NinjectSelfHostBootstrapper(
                CreateKernel,
                serviceComfiguration);
            selfHost.Start();
        }
Ejemplo n.º 3
0
 private void StartService()
 {
     lock (_lockObject)
     {
         var uplodService = NinjectWcfConfiguration.Create <ExcelUploadService, NinjectServiceSelfHostFactory>();
         var selfHost     = new NinjectSelfHostBootstrapper(
             CreateKernel,
             uplodService);
         Console.Write($"Starting the service {uplodService.BaseAddresses.SingleOrDefault()}");
         selfHost.Start();
     }
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            IKernel kernel = new StandardKernel(new ServiceModule());

            NinjectWcfConfiguration dollarConverterServiceConfig =
                NinjectWcfConfiguration.Create <DollarConverterService, NinjectServiceSelfHostFactory>();

            using (var selfHost = new NinjectSelfHostBootstrapper(() => kernel
                                                                  , dollarConverterServiceConfig))
            {
                selfHost.Start();
                Console.Write("All Services Started. Press \"Enter\" to stop thems...");
                Console.ReadLine();
            }
        }
Ejemplo n.º 5
0
 static void Main(string[] args)
 {
     try
     {
         var chatServiceConfiguration = NinjectWcfConfiguration.Create <ChatService, NinjectServiceSelfHostFactory>();
         using (var host = new NinjectSelfHostBootstrapper(CreateKernel, chatServiceConfiguration))
         {
             host.Start();
             Console.ReadKey();
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// The application main method.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            var webApiConfiguration = new HttpSelfHostConfiguration("http://localhost:8080");

            webApiConfiguration.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{id}",
                defaults: new { id = RouteParameter.Optional, controller = "values" });

            using (var selfHost = new NinjectSelfHostBootstrapper(CreateKernel, webApiConfiguration))
            {
                selfHost.Start();
                Console.WriteLine("Press Enter to quit.");
                Console.ReadLine();
            }
        }
Ejemplo n.º 7
0
        private static NinjectSelfHostBootstrapper CreateAndStartTestService(TestServiceConfiguration config, IKernel kernel)
        {
            var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                SendTimeout = TimeSpan.FromSeconds(10)
            };
            var address   = new Uri(BaseUrl, config.Id);
            var wcfConfig = NinjectWcfConfiguration.Create <DefaultTestService, NinjectServiceSelfHostFactory>(
                h => h.AddServiceEndpoint(typeof(ITestService), binding, address));

            var host = new NinjectSelfHostBootstrapper(() => kernel, wcfConfig);

            if (!kernel.GetAll <INinjectSelfHost>().Any())
            {
                throw new TestServiceException("Can't start test service because no instances of `INinjectSelfHost` are registered");
            }
            host.Start();
            return(host);
        }
        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();
        }
Ejemplo n.º 9
0
        public static void Main(string[] args)
        {
            DbAutoMapper.Initialize();
            var webApiConfiguration = new HttpSelfHostConfiguration("http://localhost:8080");

            webApiConfiguration.MapHttpAttributeRoutes();
            var cors = new EnableCorsAttribute("*", "*", "*");

            webApiConfiguration.EnableCors(cors);
            webApiConfiguration.Formatters.JsonFormatter.MediaTypeMappings
            .Add(new System.Net.Http.Formatting.RequestHeaderMapping("Accept",
                                                                     "text/html",
                                                                     StringComparison.InvariantCultureIgnoreCase,
                                                                     true,
                                                                     "application/json"));

            using (var selfHost = new NinjectSelfHostBootstrapper(CreateKernel, webApiConfiguration))
            {
                selfHost.Start();
                Console.WriteLine("Press Enter to quit.");
                Console.ReadLine();
            }
            Console.WriteLine("Buka");
        }