zoukankan      html  css  js  c++  java
  • Net Core的启动项Program(2)

        
    namespace ConsoConfiguration
    {
        public class Program
        {
    
            //Configuration: Represents a set of key/value application configuration properties.
            //表示一组键/值 应用程序配置属性
            private static IConfiguration Configuration { set; get; }
    
            static void Main(string[] args)
            {
    
                //ConfigurationBuilder:Used to build key/value based configuration settings for use in an application
                //用于生成基于键/值的配置设置,以便在应用程序中使//这个主要用于配置管理
                var Configure = new ConfigurationBuilder();
                Configure.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
                //Build==》Configure
                var configuration = Configure.Build();//启动
                var GetSectionValue = configuration.GetSection("ConnectionStrings").GetValue<string>("wms");
                var GetConnectionStringValue = configuration.GetConnectionString("wms");
                //↑↑↑上面是把基于Key/Value的配置给配置好了↑↑↑↑↑↑↑↑↑↑↑
    
                //↓↓↓给Host添加所需要的服务↓↓↓↓↓↓
                var builder = new HostBuilder();
                //配置Loggering的服务
                builder.ConfigureLogging((hostbuildercontext, loggering) =>
                {
                    loggering.AddConsole();
                });
    
                //配置Services的服务
                //ConfigureServices:Adds services to the container. This can be called multiple times and the results  will be additive.
                //向容器添加服务。这可以多次调用,结果将是相加的
                builder.ConfigureServices((hostbuildercontext, ServicesCollections) =>
                {
                    //hostbuildercontext.Configuration:
                    //这个Microsoft.Extensions.Configuration.IConfiguration包含应用程序和Microsoft.Extensions.Hosting.i主机。
                    Configuration = hostbuildercontext.Configuration;
    //链接SqlConnectionString ServicesCollections.AddDbContext
    <WMSContext>(o => o.UseSqlServer(configuration.GetSection("").GetValue<string>(""))); //常见的服务NuGet ServicesCollections.AddHttpClient(); ServicesCollections.AddOptions(); //生命周期 ServicesCollections.AddSingleton(Configuration); }); //Build==》用来启动Host var host = builder.Build(); using (host) { host.Run(); } Console.WriteLine("Hello World!"); } } }
    {
      "ConnectionStrings": {
        "wms": "Data Source=;Initial Catalog=WMS;Persist Security Info=True;User ID=wms;Password=",  
        "acc_hub": "Data Source=;pwd=;uid=sa;database=;"
      },
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft": "Warning",
          "Microsoft.Hosting.Lifetime": "Information"
        }
      },
      "AppSettings": {
        "Name": "tom",
        "Age": "15"
      },
      "AllowedHosts": "*"
    }
    人各有命,上天注定,有人天生为王,有人落草为寇。脚下的路,如果不是你自己的选择,那么旅程的终点在哪,也没人知道。你会走到哪,会遇到谁,都不一定。
  • 相关阅读:
    【Java】增强的for流程
    xxxxx
    lyphtesttest rename of file
    lyphtesttest winmerge class の比較
    lyphtesttest sql of system session
    lyphtesttest 常用ファイルの操作、検索。excelの操作  java
    Maven3(2.集成maven插件到eclipse(包含eclipse安装svn步骤))
    Maven3(1.下载maven安装与配置)
    centos6 安装hbase+hadoop单机版
    centos6 安装jdk1.6
  • 原文地址:https://www.cnblogs.com/ZkbFighting/p/13589367.html
Copyright © 2011-2022 走看看