1-创建一个空的dotnet mvc网站

2- 创建appsettings.json文件, 这文件会默认被绑定

{
"ClassNo": "1",
"ClassDesc": "Asp.net core",
"Students": [
{
"name": "lili",
"age": "11"
},
{
"name": "xiaofeng",
"age": "33"
},
{
"name": "xiaobao",
"age": "66"
}
]
}

  3-创建一个可映射的class类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; namespace optionBindingDemo
{
public class Classes
{
public string ClassNo { get; set; } public string ClassDesc { get; set; } public List<Student> Students { get; set; }
} public class Student
{
public string Age { get; set; }
public string Name { get; set; }
}
}

4-开始绑定

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration; namespace optionBindingDemo
{
public class Startup
{
IConfiguration Configuration;
public Startup(IConfiguration configuration)
{
this.Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
Classes cls = new Classes();
this.Configuration.Bind(cls);
app.Run(async (context) =>
{
await context.Response.WriteAsync($"ClassNo: {cls.ClassNo}");
await context.Response.WriteAsync($"ClassDesc: {cls.ClassDesc}");
await context.Response.WriteAsync($"studentListCount: {cls.Students.Count}");
});
}
}
}

12-optionBinding的更多相关文章

  1. python 各模块

    01 关于本书 02 代码约定 03 关于例子 04 如何联系我们 1 核心模块 11 介绍 111 内建函数和异常 112 操作系统接口模块 113 类型支持模块 114 正则表达式 115 语言支 ...

  2. Python Standard Library

    Python Standard Library "We'd like to pretend that 'Fredrik' is a role, but even hundreds of vo ...

  3. 在mybatis中写sql语句的一些体会

    本文会使用一个案例,就mybatis的一些基础语法进行讲解.案例中使用到的数据库表和对象如下: article表:这个表存放的是文章的基础信息 -- ------------------------- ...

  4. AndroidStudio — Error:Failed to resolve: junit:junit:4.12错误解决

    原博客:http://blog.csdn.net/u013443865/article/details/50243193 最近使用AndroidStudio出现以下问题: 解决:打开app下的buil ...

  5. 读过MBA的CEO更自私?《哈佛商业评论》2016年第12期。4星

    老牌管理杂志.每期都值得精度.本期我还是给4星. 以下是本书中的一些内容的摘抄: 1:他们发现在Airbnb上,如果客人姓名听起来像黑人,那么比名字像白人的客人的接受率会低16%.#45 2:对立组织 ...

  6. 12个小技巧,让你高效使用Eclipse

    集成开发环境(IDE)让应用开发更加容易.它们强调语法,让你知道是否你存在编译错误,在众多的其他事情中允许你单步调试代码.像所有的IDE一 样,Eclipse也有快捷键和小工具,这些会让您感觉轻松许多 ...

  7. 第12章 Linux系统管理

    1. 进程管理 1.1 进程查看 (1)进程简介 进程是正在执行的一个程序或命令(如ls命令也是一个进程),每个进程都是一个运行的实体,都有自己的地址空间,并占用一定的系统资源. (2)进程管理的作用 ...

  8. Jexus Web Server 完全傻瓜化图文配置教程(基于Ubuntu 12.04.3 64位)[内含Hyper-v 2012虚拟机镜像下载地址]

    1. 前言 近日有感许多新朋友想尝试使用Jexus,不过绝大多数都困惑徘徊在Linux如何安装啊,如何编译Mono啊,如何配置Jexus啊...等等基础问题,于是昨日向宇内流云兄提议,不如搞几个配置好 ...

  9. CSharpGL(12)用T4模板生成CSSL及其renderer代码

    CSharpGL(12)用T4模板生成CSSL及其renderer代码 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharpGL源码中包含10多个独立 ...

  10. ABP(现代ASP.NET样板开发框架)系列之12、ABP领域层——工作单元(Unit Of work)

    点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之12.ABP领域层——工作单元(Unit Of work) ABP是“ASP.NET Boilerplate Pr ...

随机推荐

  1. OC跟Swift混编

    OC项目中使用Swift 本文版权归作者所有,如需转载请联系孟祥月 CSDN博客:http://blog.csdn.net/mengxiangyue  独立博客:http://mengxiangyue ...

  2. C#实现屏幕指定区域截屏

    //string Opath = @"C:/Picture";            //if (Opath.Substring(Opath.Length - 1, 1) != @ ...

  3. python3绘图示例4(基于matplotlib:箱线图、散点图等)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from matplotlib.pyplot import * x=[1,2,3,4]y=[5,4,3,2] # ...

  4. 西门子(SIEMENS)软件安装时需要重启的解决方法,regedit restart

    打开注册表(regedit) 删除注册表项 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manage\PendingFile ...

  5. java Date equals 的坑

    今天在JDK6上做开发,遇到一个很诡异的问题. Domain中一个实体是Date,称为变量 a, 使用Calendar构造出来的Date,称为变量b, 虽然都是同一天,比如 2016-11-11 00 ...

  6. IOS 加载更多数据中

    /**点击添加*/ - (IBAction)loadBtnClick { //1.隐藏加载按钮 self.loadBtn.hidden=YES; //2.显示“正在加载” self.loadingVi ...

  7. IOS 拼接按钮文字

    NSMutableString *tempAnswerTitle=[[NSMutableString alloc]init]; for(UIButton *answerBtn in self.answ ...

  8. 1.08 在select语句使用条件逻辑

    问题:要在select语句中,对数值执行if-else操作.例如,要产生一个结果集,如果一个员工工资小于等于2000美金,就返回消息”underpaid”:如果大于等于4000美金:就返回消息”ove ...

  9. Codeforces Round #404 (Div. 2) ABC

    A. Anton and Polyhedrons Anton's favourite geometric figures are regular polyhedrons. Note that ther ...

  10. 木棒,POJ(1011)

    题目链接:http://poj.org/problem?id=1011 解题报告: #include <cstdio> #include <cstring> #include ...