12-optionBinding
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的更多相关文章
- python 各模块
01 关于本书 02 代码约定 03 关于例子 04 如何联系我们 1 核心模块 11 介绍 111 内建函数和异常 112 操作系统接口模块 113 类型支持模块 114 正则表达式 115 语言支 ...
- Python Standard Library
Python Standard Library "We'd like to pretend that 'Fredrik' is a role, but even hundreds of vo ...
- 在mybatis中写sql语句的一些体会
本文会使用一个案例,就mybatis的一些基础语法进行讲解.案例中使用到的数据库表和对象如下: article表:这个表存放的是文章的基础信息 -- ------------------------- ...
- AndroidStudio — Error:Failed to resolve: junit:junit:4.12错误解决
原博客:http://blog.csdn.net/u013443865/article/details/50243193 最近使用AndroidStudio出现以下问题: 解决:打开app下的buil ...
- 读过MBA的CEO更自私?《哈佛商业评论》2016年第12期。4星
老牌管理杂志.每期都值得精度.本期我还是给4星. 以下是本书中的一些内容的摘抄: 1:他们发现在Airbnb上,如果客人姓名听起来像黑人,那么比名字像白人的客人的接受率会低16%.#45 2:对立组织 ...
- 12个小技巧,让你高效使用Eclipse
集成开发环境(IDE)让应用开发更加容易.它们强调语法,让你知道是否你存在编译错误,在众多的其他事情中允许你单步调试代码.像所有的IDE一 样,Eclipse也有快捷键和小工具,这些会让您感觉轻松许多 ...
- 第12章 Linux系统管理
1. 进程管理 1.1 进程查看 (1)进程简介 进程是正在执行的一个程序或命令(如ls命令也是一个进程),每个进程都是一个运行的实体,都有自己的地址空间,并占用一定的系统资源. (2)进程管理的作用 ...
- Jexus Web Server 完全傻瓜化图文配置教程(基于Ubuntu 12.04.3 64位)[内含Hyper-v 2012虚拟机镜像下载地址]
1. 前言 近日有感许多新朋友想尝试使用Jexus,不过绝大多数都困惑徘徊在Linux如何安装啊,如何编译Mono啊,如何配置Jexus啊...等等基础问题,于是昨日向宇内流云兄提议,不如搞几个配置好 ...
- CSharpGL(12)用T4模板生成CSSL及其renderer代码
CSharpGL(12)用T4模板生成CSSL及其renderer代码 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharpGL源码中包含10多个独立 ...
- ABP(现代ASP.NET样板开发框架)系列之12、ABP领域层——工作单元(Unit Of work)
点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之12.ABP领域层——工作单元(Unit Of work) ABP是“ASP.NET Boilerplate Pr ...
随机推荐
- HTTP杂记
HTTP请求中的浏览器Timing信息: stalled:浏览器发出请求到这个请求可以发出的等待时间 proxy negotiation: 代理协商的时间 request sent:请求的第一个字节发 ...
- Design Pattern ->Bridge
Layering & Contract Philosophy With additional indirection. class CWindowImp { public: virtual v ...
- Eclipse + Tomcat 环境下配置 JSTL 标签
1.下载 jar 包. 网址:http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/ 2.解压后将jstl.jar和stan ...
- jmeter之HTTP信息头管理器
信息头管理器作用: HTTP信息头管理器在Jmeter的使用过程中起着很重要的作用,通常我们在通过Jmeter向服务器发送http请求(get或者post)的时候,往往后端需要一些验证信息,比如说we ...
- 带来全新的网络格局---html5
自从HTML5诞生之后,就是开始建立了一个标准的原则,那就是所有的技术它必须是面向开放,并不能有专利的一个存在,在整个期间Opera捐献了css技术,而google的话则是给开发者提供了视频的webM ...
- 笨办法学Python(八)
习题 8: 打印,打印 formatter = "%r %r %r %r" print formatter % (1, 2, 3, 4) print formatter % (&q ...
- gcc常用参数列举
[参数详解] -c 只激活预处理,编译,和汇编,也就是他只把程序做成obj文件 例子用法: gcc -c hello.c 他将生成.o的obj文件 -S 只激活预处理和编译,就是指 ...
- Android(java)学习笔记64:Android权限大全
访问登记属性 android.permission.ACCESS_CHECKIN_PROPERTIES读取或写入登记check-in数据库属性表的权限 获取错略位置 android.permissio ...
- python 爬图片
学了两天python,语法慢慢熟悉吧,数据结构都没写过. 写了一个爬图片的小东西.挺有意思的.都是女神照 (✿◡‿◡) 用的是正则表达式, ''' 符号: . 匹配任意字符,\n除外 * 匹配前一个字 ...
- 20145238-荆玉茗 《Java程序设计》第一次实验报告
实验一 Java开发环境的熟悉(Linux + Eclipse) 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. 实验要求 1.没 ...