.NET Core 1.0.1

Module Component .NET Core
MongoDB MongoDB.Driver There has a nuget package available v2.3.0.
Json Newtonsoft.Json

If you are working with Mvc, Newtonsoft.Json has been included by default.

Logging Logging
public class HomeController : Controller
{
private readonly ILogger _logger; public HomeController(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<HomeController>();
} public IActionResult Index()
{
_logger.LogInformation("Index has been called");
return View();
}
}
Logging NLog.RabbitMQ There are no nuget packages available, and in the library [MethodImpl(MethodImplOptions.Synchronized)] and Delegate.CreateDelegate are not supported by .NET Core also.
Logging NLog.Targets.ElasticSearch There are no nuget packages available, but I created one myself.
Mailing Mandrill There are no nuget packages availabe, but you can use SMTP or a small webjob without .NET Core.
Azure Storage WindowsAzure.Storage

There has a nuget package available v7.2.1.

BUT...

https://github.com/Azure/azure-storage-net/blob/master/README.md#odata

This version depends on three libraries (collectively referred to as ODataLib), which are resolved through the ODataLib (version 5.6.4) packages available through NuGet and not the WCF Data Services installer which currently contains 5.0.0 versions.

The ODataLib libraries can be downloaded directly or referenced by your code project through NuGet.

The specific ODataLib packages are:

Note: The ODataLib packages currently do not support "netstandard1.6" or "netcoreapp1.0" frameworks in projects depending on the current relase of Dotnet CoreCLR. Thus, you may encounter failures while trying to restore the ODataLib dependencies for one of the targeted frameworks mentioned above. Until the support is added, if you run into this, you can use the imports statement within the framework node of your project.json file to specify to NuGet that it can restore the packages targeting the framework within the "imports" statement as shown below:

  "imports": [
"dnxcore50",
"portable-net451+win8"
]
Azure ServiceBus WindowsAzure.ServiceBus There are no nuget packages availabe.
Identity Microsoft.AspNet.Identity.Core There has a nuget package available.
Identity Microsoft.AspNet.Identity.Owin There has a nuget package available.
Configuration (It's a big improvement for unit testing.) Configuration

appsettings.json

{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}

C#

public class LoggingConfig
{
public bool IncludeScopes { get; set; } public LogLevelConfig LogLevel { get; set; }
} public LogLevelConfig
{
public string Default { get; set; } public string System { get; set; } public string Microsoft { get; set; }
} public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
} public IConfigurationRoot Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.Configure<LoggingConfig>(Configuration.GetSection("Logging"));
services.AddMvc();
}
} public class HomeController : Controller
{
public HomeController(IOptions<LoggingConfig> loggingConfig)
{
}
}

Configuration (Switch build configuration was a hell but not an

ymore.)

Configuration per environment

You can copy appsettings.json per environment, e.g. appsettings.development.json, appsettings.staging.json, appsettings.production.json

The default code template already support this see the below code:

.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)

Based on IHostingEnvironment you can do all the magic

public class HomeController : Controller
{
public HomeController(IHostingEnvironment env)
{
var environmentName = env.EnvironmentName;
var isDevelopment = env.IsDevelopment();
var isStaging = env.IsStaging();
var isProduction = env.IsProduction();
}
}

How to switch the environment?

In the end the environment variables will be saved into launchSettings.json

Based on the below command you can switch the environment easily

dotnet run --environment "Staging"

How are we going to do with the automatically deployment?

  • Azure web apps
    In the project.json please include (appsettings.development.json, appsettings.staging.json, appsettings.production.json)

    {
    "publishOptions": {
    "include": [
    "wwwroot",
    "**/*.cshtml",
    "appsettings.json",
    "appsettings.Development.json",
    "appsettings.Staging.json",
    "appsettings.Production.json",
    "web.config"
    ]
    }

    You can add a slot setting via Azure portal see the below screenshot

    

  • Azure cloud services
    One possible way would be to run prepublish or postpublic scripts/commands
IoC Dependency injection
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<ITransientService, TransientService>();
services.AddScoped<IScopedService, ScopedService>();
services.AddSingleton<ISingletonService, SingletonService>();

services.AddMvc();
}
}

TransientTransient lifetime services are created each time they are requested. This lifetime works best for lightweight, stateless services.

ScopedScoped lifetime services are created once per request.

SingletonSingleton lifetime services are created the first time they are requested (or whenConfigureServices is run if you specify an instance there) and then every subsequent request will use the same instance. If your application requires singleton behavior, allowing the services container to manage the service’s lifetime is recommended instead of implementing the singleton design pattern and managing your object’s lifetime in the class yourself.

How to replace the default services container?

public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc(); var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterType<TransientService>().As<ITransientService>().InstancePerDependency();
containerBuilder.RegisterType<ScopedService>().As<IScopedService>().InstancePerRequest();
containerBuilder.RegisterType<SingletonService>().As<ISingletonService>().SingleInstance(); containerBuilder.Populate(services); var container = containerBuilder.Build();
return new AutofacServiceProvider(container);
}
}
Unit Tests  MSTest

"MSTest.TestFramework": "1.0.5-preview"
"dotnet-test-mstest": "1.1.1-preview" does not support .NET Core 1.0.1 yet
Unit Tests  xUnit

project.json

{
"version": "1.0.0-*", "testRunner": "xunit", "dependencies": {
"xunit": "2.2.0-beta3-build3402",
"dotnet-test-xunit": "2.2.0-preview2-build1029"
}, "frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
}
}
}
}
}
Integration tests Microsoft.AspNetCore.TestHost

There has a nuget package available v1.0.0.

Integration tests Microsoft.AspNet.WebApi.Client

There has a nuget package available v5.2.3.

Globalization and localization  

https://docs.asp.net/en/latest/fundamentals/localization.html

http://andrewlock.net/adding-localisation-to-an-asp-net-core-application (Very interesting even with a localized view)

.NET Core Analysis的更多相关文章

  1. 【python】使用flask制作小型页面的关键点总结

    目录结构 app.py web代码 store.db 存储信息的轻量数据库,用的sqlite3 schema.sql 数据库的初始化建表语句 settings.cfg 配置信息 static/styl ...

  2. jacoco统计server端功能测试覆盖率

    jacoco可以统计,功能测试时,server代码调用的覆盖情况.这里对服务器端的java代码进行统计.   操作步骤如下:   第一步:更改server的启动脚本,使用jacocoagent.jar ...

  3. ChIP-seq 核心分析 下游分析

    http://icb.med.cornell.edu/wiki/index.php/Elementolab/ChIPseeqer_Tutorial [怪毛匠子 整理] ChIP-seq[核心分析 下游 ...

  4. Importing/Indexing database (MySQL or SQL Server) in Solr using Data Import Handler--转载

    原文地址:https://gist.github.com/maxivak/3e3ee1fca32f3949f052 Install Solr download and install Solr fro ...

  5. 按需要对Androguard进行定制增强

    按需对Androguard进行增强和定制修改 Androguard是一个对android应用程序进行分析的基于python的平台,功能强大.但是在使用的过程中,提供的功能不一定如我们所需,所以需要进行 ...

  6. Solr 6.7学习笔记(03)-- 样例配置文件 solrconfig.xml

    位于:${solr.home}\example\techproducts\solr\techproducts\conf\solrconfig.xml <?xml version="1. ...

  7. HubbleDotNet 使用类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using Hubble.S ...

  8. lucene-5.3.1配置(win7x64)

    lucene下载地址:http://www.us.apache.org/dist/lucene/java/5.3.1/lucene-5.3.1.zip 下载之后解压 控制台应用程序下配置: 找到luc ...

  9. Solr基础知识二(导入数据)

    上一篇讲述了solr的安装启动过程,这一篇讲述如何导入数据到solr里. 一.准备数据 1.1 学生相关表 创建学生表.学生专业关联表.专业表.学生行业关联表.行业表.基础信息表,并创建一条小白的信息 ...

随机推荐

  1. /var/run/yum.pid 已被锁定,PID 为 XXXX 的另一个程序正在运行。

    安装st-load时, 终端提示 “/var/run/yum.pid 已被锁定,PID 为 13908 的另一个程序正在运行.” 解决方法:直接在终端运行 rm -f /var/run/yum.pid ...

  2. MIT 6.828 JOS学习笔记7. Lab 1 Part 2.2: The Boot Loader

    Lab 1 Part 2 The Boot Loader Loading the Kernel 我们现在可以进一步的讨论一下boot loader中的C语言的部分,即boot/main.c.但是在我们 ...

  3. BDYY【面试题】

    1.引用与多态的关系:引用是除指针外另一个可以产生多态效果的手段.这意味着,一个基类的引用可以指向它的派生类实例. 2.C++可以多继承 3.引用与指针区别:

  4. BZOJ2471 : Count

    考虑KMP,设$f[i][j][S]$表示还剩最低$i$位没有确定,目前KMP匹配到了$j$这个位置,前缀匹配情况是$S$,最终会匹配到哪里,中途匹配成功几次. 其中$S[i]$是一个pair< ...

  5. react学习小结(生命周期- 实例化时期 - 存在期- 销毁时期)

    react学习小结   本文是我学习react的阶段性小结,如果看官你是react资深玩家,那么还请就此打住移步他处,如果你想给一些建议和指导,那么还请轻拍~ 目前团队内对react的使用非常普遍,之 ...

  6. Leetcode jump Game

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  7. 【Eclipse】 Eclipse 中JPEGEncodeParam 错误波浪线问题

    [异常信息] Description Resource Path Location Type Access restriction: The method encode(BufferedImage, ...

  8. vs 2015 连接不上tfs 错误代码:TF31002

    在vs2015里面怎么也连接不上,把地址放到浏览器里可以打开,所以点击右边的 在visual studio 中打开,然后将源码映射到本地

  9. java 打印流(PrintStream)

    打印流(PrintStream):打印流可以打印任意类型的数据,而且打印流在打印数据之前会将数据转为字符串在进行打印 PrintStream可以接受文件和其他字节输出流,所以打印流是对普通字节输出流的 ...

  10. js模版引擎handlebars.js实用教程——为什么选择Handlebars.js

    返回目录 据小菜了解,对于java开发,涉及到页面展示时,比较主流的有两种解决方案: 1. struts2+vo+el表达式. 这种方式,重点不在于struts2,而是vo和el表达式,其基本思想是: ...