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": "*"
    }
    人各有命,上天注定,有人天生为王,有人落草为寇。脚下的路,如果不是你自己的选择,那么旅程的终点在哪,也没人知道。你会走到哪,会遇到谁,都不一定。
  • 相关阅读:
    [DB] 数据库的连接
    JS leetcode 翻转字符串里的单词 题解分析
    JS leetcode 拥有最多糖果的孩子 题解分析,六一快乐。
    JS leetcode 搜索插入位置 题解分析
    JS leetcode 杨辉三角Ⅱ 题解分析
    JS leetcode 寻找数组的中心索引 题解分析
    JS leetcode 移除元素 题解分析
    JS leetcode 最大连续1的个数 题解分析
    JS leetcode 两数之和 II
    JS leetcode 反转字符串 题解分析
  • 原文地址:https://www.cnblogs.com/ZkbFighting/p/13589367.html
Copyright © 2011-2022 走看看