SlideShare une entreprise Scribd logo
1  sur  35
C# ON LINUX
Our experience
Different naming
■ ASP.NET 5
■ ASP.NET MVC 6
■ ASP.NET vNext
■ ASP.NETCore 1
Visual studio changes
The Node Package Manager is fully integrated with Visual Studio to provide a more natural user workflow.
GRUNT / GULP / BOWER Integration
Task Runner
Explorer
Current status
■ ASP.NET 5 has been renamed to ASP.NET Core 1.0
■ May 16, 2016 - Announcing ASP.NET Core RC2
■ https://docs.asp.net/en/latest/
■ https://blogs.msdn.microsoft.com/webdev/
Runtime platforms
■ Classical .Net Framework.As always, it can be run on windows.
■ .Net Core.This is cross-platform environment officially developed and supported by
Microsoft.Can be installed on windows, linux and Mac.
■ Mono.This is open-source cross-platform port of .NET Framework for non-windows
systems. It is not officially supported by Microsoft and probably slower than .Net Core.
Web application
■ No more XML configuration, configuration now in JSON
■ Project.json as common project definition file
■ Startup.cs as entry point of application
■ Microsoft.AspNet.Server.Kestrel as running web server
■ All usings are Nuget packages
■ No more required csproj file, all files will be included in build
■ Web application = self-hostable console-application
Project.json
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Caching.Abstractions": "1.0.0-rc1-final",
"Microsoft.Extensions.Caching.Memory": "1.0.0-rc1-final",
"System.Console": "4.0.0-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"Trkd.Dnx.Proxy": "1.0.0-*",
"ActiveMashups.Core": "1.0.0-*",
"System.Runtime": "4.0.21-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq.Queryable": "4.0.1-beta-23516",
"System.Linq.Parallel": "4.0.1-beta-23516",
"System.Threading.Tasks": "4.0.11-beta-23516",
"System.Runtime.Serialization.Primitives": "4.1.0-beta-23516“
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnxcore50": {
}
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
],
"scripts": {
"postpublish": "%project:Directory%/postpublish/postpublish.bat"
}
}
"frameworks": {
"dnxcore50": { // .Net Core
},
"dnx461" :{ // mono
},
"net461" :{ // .Net Framework
}
}
Many platforms in-time development
Startup.cs
public class Startup
{
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder().AddJsonFile("Configuration/AppSettings.json").AddEnvironmentVariables();
this.Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; set; }
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
// 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.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseStaticFiles();
app.UseMvc();
}
}
Configuration loading
Services, filters, options, dependency injection, etc
Logging, middleware, routing
Configuration loading
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("Configuration/AppSettings.json")
.AddJsonFile("Configuration/AmqpLoggingSettings.json")
.AddEnvironmentVariables();
this.Configuration = builder.Build();
this.Configuration["WebRootPath"] = env.WebRootPath;
this.Configuration["AppRootPath"] = appEnv.ApplicationBasePath;
}
RC1
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();
}
RC2
Services, filters, options, dependency injection…
// 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.AddMvc(
mvcOptions =>
{
mvcOptions.Filters.Add(typeof(GlobalExceptionInterseptor));
mvcOptions.Filters.Add(typeof(JsonWebTokenAuthentification));
});
ConfigureOptions(services);
ConfigureDependencyInjection(services);
}
Request filter
public class JsonWebTokenAuthentification : ActionFilterAttribute
{
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
// if AllowAnonymous attribute is present - skip other checks
if (context.Filters.OfType<AllowAnonymousFilter>().Any())
{
await next();
return;
}
else
{
context.Result = new HttpUnauthorizedResult();
return;
}
}
Options model – load configuration
https://docs.asp.net/en/latest/fundamentals/configuration.html#using-options-and-configuration-objects
{
"AmqpLoggerConfiguration": {
"ServerAddress": "http://localhost:15672",
"UserName": "guest",
"Password": "guest",
"VirtualHost": "%2f",
"ExchangeName": "gelf.fanout",
"Facility": “MyApplication"
}
} AmqpLoggingSettings.json
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("Configuration/AppSettings.json")
.AddJsonFile("Configuration/AmqpLoggingSettings.json")
.AddEnvironmentVariables();
this.Configuration = builder.Build();
Options model – bind to classes throught DI
public class AmqpLoggerOptions
{
public string ServerAddress { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public string VirtualHost { get; set; }
public string ExchangeName { get; set; }
public string Facility { get; set; }
}
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.Configure<AmqpLoggerOptions>(Configuration.GetSection("AmqpLoggerConfiguration"));
}
Startup.cs
public class AmqpLogger : ILogger
{
private readonly RabbitMqLogger logger;
private readonly AmqpLoggerOptions amqpOptions;
public AmqpLogger(IOptions<AmqpLoggerOptions> options)
{
amqpOptions = options.Value;
var rabbitOptions = Mapper.Map<RabbitMqLoggerOptions>(amqpOptions);
logger = new RabbitMqLogger(rabbitOptions);
}
public async Task<Guid> LogAsync(IActiveMashupsLogEntry logEntry)
{
var logMessage = CreateMessageWithDefaultFields(logEntry);
var loggingSucceed = await logger.LogMessage(logMessage);
if (!loggingSucceed)
{
throw new Exception("Failed to send logs to amqp");
}
return logMessage.Id;
}
Options model - usage
Build-in DI
Build-in Dependency Injection
https://docs.asp.net/en/latest/fundamentals/dependency-injection.html
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc(
mvcOptions =>
{
mvcOptions.Filters.Add(typeof(GlobalExceptionInterseptor));
mvcOptions.Filters.Add(typeof(JsonWebTokenAuthentification));
});
ConfigureOptions(services);
services.AddSingleton<AmqpLogger>();
services.AddSingleton<FileLogger>();
services.AddTransient<ILogger, AmqpAndFileLogger>();
services.AddSingleton<ITokensManager, TrkdTokensManager>();
}
Startup.cs
Dependency Injection - Service Lifetimes
ASP.NET services can be configured with the following lifetimes:
■ Transient - Transient lifetime services are created each time they are requested. This
lifetime works best for lightweight, stateless services.
■ Scoped - Scoped lifetime services are created once per request.
■ Singleton - Singleton lifetime services are created the first time they are requested (or
when ConfigureServices 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.
Logging, middleware, routing
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMiddleware<LogBadResponsesAsWarningsMiddleware>();
app.UseMiddleware<ContentLengthResponseHeaderWriterMiddleware>();
app.UseStaticFiles();
app.UseMvc(routes =>
{
// add the new route here.
routes.MapRoute(name: "areaRoute",
template: "{area:exists}/{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
Startup.cs
Middleware (ex HTTP Module)
https://docs.asp.net/en/latest/fundamentals/middleware.html
Middleware example
public class ContentLengthResponseHeaderWriterMiddleware
{
private readonly RequestDelegate next;
public ContentLengthResponseHeaderWriter(RequestDelegate next)
{
this.next = next;
}
public async Task Invoke(HttpContext context)
{
using (var buffer = new MemoryStream())
{
var response = context.Response;
var bodyStream = response.Body;
response.Body = buffer;
await this.next(context);
var lenght = buffer.Length;
if (lenght > 0)
{
response.Headers.Add("Content-Length", new[] { lenght.ToString() });
}
buffer.Position = 0;
await buffer.CopyToAsync(bodyStream);
}
}
}
United controller
[Area("Portfolios")]
[Route("[controller]")]
public class PortfoliosController : Controller
{
public async Task<object> Get()
{
return await new GetPortfoliosWorkflow(this.HttpContext).ExecuteAsync(null);
}
[HttpGet("{portfolioId}")]
public async Task<object> Get(long portfolioId)
{
return await new GetSinglePortfolioWorkflow(this.HttpContext).ExecuteAsync(portfolioId);
}
[HttpPost]
public async Task<object> Post([FromBody]PortfolioViewModel portfolioViewModel)
{
var result = await new CreatePortfolioWorkflow(this.HttpContext).ExecuteAsync(portfolioViewModel);
var locationHeader = HttpContext.Request.GetDisplayUrl() + "/" + result.PortfolioId;
return Created(locationHeader, result);
}
[HttpPut("{portfolioId}")]
public async Task<object> Put(long portfolioId, [FromBody]PortfolioViewModel portfolioViewModel)
{
if (portfolioViewModel.PortfolioId != 0 && portfolioViewModel.PortfolioId != portfolioId)
{
return new BadRequestObjectResult("Portfolio id from url is not equal to portfolio id from request");
}
portfolioViewModel.PortfolioId = portfolioId;
return await new UpdatePortfolioWorkflow(this.HttpContext).ExecuteAsync(portfolioViewModel);
}
Kestrel
■ Kestrel is a cross-platform web server based on libuv, a cross-platform asynchronous I/O library.
■ You add support for Kestrel by including Microsoft.AspNet.Server.Kestrel in your project’s
dependencies listed in project.json.
■ https://github.com/aspnet/KestrelHttpServer
https://docs.asp.net/en/latest/fundamentals/servers.html
CLITools
■ The DNX Utility (DNU) tool is responsible for all operations involved with packages in
your application.
■ Dotnet version manager (DNVM) is responsible for downloading and installation
environment runtimes.
■ DNX is .NET Execution Environment that will execute your application.
Dotnet version manager (DNVM)
You can install any environment that is available on platform you are using.
Some useful cli commands:
■ dnvm list - will show you list of available installer runtimes, their aliases and current default runtime
(marked by *)
■ dnvm install - installs requested runtime (example - dnvm install latest -r coreclr -acrh x64)
■ dnvm use - selects specific runtime as default
(examples - dnvm use default; dnvm use 1.0.0-rc1-update1 -r coreclr -acrh x64)
The DNX Utility (DNU)
■ DNU restore - restores nuget pakages
■ DNU publish - will package your application into a self-contained directory that can
be launched. It will create the following directory structure
output/
output/packages
output/appName
output/commandName.cmd
Note, that DNU can be unavailable if there is no runtime selected in DNVM (even if
runtimes are installed).
.NET Execution Environment (DNX)
In common case it's only used to run you app by execution from directory with
project.json file:
■ dnx web - for web app
■ dnx run - for console app
CLI tools from RC 1 to RC 2
DNVM, DNU, DNX = > Dotnet
DNX command CLI command Description
dnx run dotnet run Run code from source.
dnu build dotnet build Build an IL binary of your code.
dnu pack dotnet pack Package up a NuGet package of your code.
dnx [command] (for example, "dnx web") N/A* In DNX world, run a command as defined in the project.json.
dnu install N/A* In the DNX world, install a package as a dependency.
dnu restore dotnet restore Restore dependencies specified in your project.json.
dnu publish dotnet publish
Publish your application for deployment in one of the three forms (portable,
portable with native and standalone).
dnu wrap N/A* In DNX world, wrap a project.json in csproj.
dnu commands N/A* In DNX world, manage the globally installed commands.
(*) - these features are not supported in the CLI by design.
Known issues
■ Kestrel do not set content-length header in response.
If your component needs this header (for example, java-based vert.x uses content-length
to read message body), add middleware as workaround.
■ While working with 3rd party datasources, especially withWCF SOAP (IIS) services,
server can send response with GZipped content + content-length (header) of GZipped
body.
System libs fails to deserialize response body, they UZipping body, but reads it using
content-length header of GZipped body.
Thus, body can be read only by half of its contents.
RC2, RTM and future
QUESTIONS?
Thanks!
MAKSIM VOLK
Software Engineer
Office: +375 17 389 0100 x 40673 Cell: +375 29 365 6597 Email: maksim_volk@epam.com
Minsk, Belarus (GMT+3) epam.com

Contenu connexe

Tendances

Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2Fabio Collini
 
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?Julian Robichaux
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycleDhruvin Nakrani
 
Making React Native UI Components with Swift
Making React Native UI Components with SwiftMaking React Native UI Components with Swift
Making React Native UI Components with SwiftRay Deck
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoasZeid Hassan
 
Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90minsLarry Cai
 
Spring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationSpring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationsourabh aggarwal
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Testing - Selenium? Rich-Clients? Containers?
Testing - Selenium? Rich-Clients? Containers?Testing - Selenium? Rich-Clients? Containers?
Testing - Selenium? Rich-Clients? Containers?Tobias Schneck
 
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4Rob Tweed
 
Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentationsourabh aggarwal
 
EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...
EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...
EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...Rob Tweed
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleSkills Matter
 
Declarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleDeclarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleFelix Meschberger
 
Overview of Node JS
Overview of Node JSOverview of Node JS
Overview of Node JSJacob Nelson
 

Tendances (20)

Serverless Java on Kubernetes
Serverless Java on KubernetesServerless Java on Kubernetes
Serverless Java on Kubernetes
 
Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2
 
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Making React Native UI Components with Swift
Making React Native UI Components with SwiftMaking React Native UI Components with Swift
Making React Native UI Components with Swift
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoas
 
JEE Programming - 04 Java Servlets
JEE Programming - 04 Java ServletsJEE Programming - 04 Java Servlets
JEE Programming - 04 Java Servlets
 
Angular beans
Angular beansAngular beans
Angular beans
 
Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90mins
 
Spring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationSpring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentation
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
OpenCms Days 2014 - Updating to OpenCms 9.5
OpenCms Days 2014 - Updating to OpenCms 9.5OpenCms Days 2014 - Updating to OpenCms 9.5
OpenCms Days 2014 - Updating to OpenCms 9.5
 
Testing - Selenium? Rich-Clients? Containers?
Testing - Selenium? Rich-Clients? Containers?Testing - Selenium? Rich-Clients? Containers?
Testing - Selenium? Rich-Clients? Containers?
 
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
 
Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentation
 
EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...
EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...
EWD 3 Training Course Part 13: Putting Everything so far into Practice using ...
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: Gradle
 
Declarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleDeclarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi Style
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
Overview of Node JS
Overview of Node JSOverview of Node JS
Overview of Node JS
 

En vedette

EC221_complete
EC221_completeEC221_complete
EC221_completeJohn Hunt
 
Contaminación del agua y del aire
Contaminación del agua y del aireContaminación del agua y del aire
Contaminación del agua y del airemiguel montaño
 
Finished_Individual_Finance_Report
Finished_Individual_Finance_ReportFinished_Individual_Finance_Report
Finished_Individual_Finance_ReportJohn Hunt
 
Poor listening styles
Poor listening stylesPoor listening styles
Poor listening styles5922001666
 
Pecha kucha finished
Pecha kucha finishedPecha kucha finished
Pecha kucha finishedJohn Hunt
 
Swiss Retail Forum 2015 - La digitalisation du point de vente est en marche
Swiss Retail Forum 2015 - La digitalisation du point de vente est en marcheSwiss Retail Forum 2015 - La digitalisation du point de vente est en marche
Swiss Retail Forum 2015 - La digitalisation du point de vente est en marcheUNIVERSRETAIL
 

En vedette (9)

vineet ku sharma
vineet ku sharmavineet ku sharma
vineet ku sharma
 
EC221_complete
EC221_completeEC221_complete
EC221_complete
 
Jasper Resume
Jasper ResumeJasper Resume
Jasper Resume
 
Contaminación del agua y del aire
Contaminación del agua y del aireContaminación del agua y del aire
Contaminación del agua y del aire
 
Finished_Individual_Finance_Report
Finished_Individual_Finance_ReportFinished_Individual_Finance_Report
Finished_Individual_Finance_Report
 
Poor listening styles
Poor listening stylesPoor listening styles
Poor listening styles
 
Pecha kucha finished
Pecha kucha finishedPecha kucha finished
Pecha kucha finished
 
Krishnan Ramachandran
Krishnan RamachandranKrishnan Ramachandran
Krishnan Ramachandran
 
Swiss Retail Forum 2015 - La digitalisation du point de vente est en marche
Swiss Retail Forum 2015 - La digitalisation du point de vente est en marcheSwiss Retail Forum 2015 - La digitalisation du point de vente est en marche
Swiss Retail Forum 2015 - La digitalisation du point de vente est en marche
 

Similaire à C#on linux

Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Steven Smith
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteorSapna Upreti
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
Academy PRO: ASP .NET Core
Academy PRO: ASP .NET Core Academy PRO: ASP .NET Core
Academy PRO: ASP .NET Core Binary Studio
 
Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfRed Hat
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsSebastian Springer
 
ASP.NET Core 1.0
ASP.NET Core 1.0ASP.NET Core 1.0
ASP.NET Core 1.0Ido Flatow
 
ASP.NET Core Web API documentation web application
ASP.NET Core Web API documentation web applicationASP.NET Core Web API documentation web application
ASP.NET Core Web API documentation web applicationAMARAAHMED7
 
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfDevfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfKAI CHU CHUNG
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "FDConf
 
SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4Jon Galloway
 
Better Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web ServicesBetter Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web ServicesWSO2
 
OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopleffen
 
Spring5 New Features
Spring5 New FeaturesSpring5 New Features
Spring5 New FeaturesJay Lee
 
Deploying windows containers with kubernetes
Deploying windows containers with kubernetesDeploying windows containers with kubernetes
Deploying windows containers with kubernetesBen Hall
 

Similaire à C#on linux (20)

Api RESTFull
Api RESTFullApi RESTFull
Api RESTFull
 
Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Academy PRO: ASP .NET Core
Academy PRO: ASP .NET Core Academy PRO: ASP .NET Core
Academy PRO: ASP .NET Core
 
Meetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdfMeetup 2022 - APIs with Quarkus.pdf
Meetup 2022 - APIs with Quarkus.pdf
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.js
 
ASP.NET Core 1.0
ASP.NET Core 1.0ASP.NET Core 1.0
ASP.NET Core 1.0
 
ASP.NET Core Web API documentation web application
ASP.NET Core Web API documentation web applicationASP.NET Core Web API documentation web application
ASP.NET Core Web API documentation web application
 
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfDevfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
 
Express node js
Express node jsExpress node js
Express node js
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
 
5.node js
5.node js5.node js
5.node js
 
SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4
 
Better Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web ServicesBetter Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web Services
 
OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshop
 
Spring5 New Features
Spring5 New FeaturesSpring5 New Features
Spring5 New Features
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
Asp.net tips
Asp.net tipsAsp.net tips
Asp.net tips
 
Deploying windows containers with kubernetes
Deploying windows containers with kubernetesDeploying windows containers with kubernetes
Deploying windows containers with kubernetes
 

Dernier

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Dernier (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

C#on linux

  • 1. C# ON LINUX Our experience
  • 2. Different naming ■ ASP.NET 5 ■ ASP.NET MVC 6 ■ ASP.NET vNext ■ ASP.NETCore 1
  • 3. Visual studio changes The Node Package Manager is fully integrated with Visual Studio to provide a more natural user workflow.
  • 4. GRUNT / GULP / BOWER Integration
  • 6. Current status ■ ASP.NET 5 has been renamed to ASP.NET Core 1.0 ■ May 16, 2016 - Announcing ASP.NET Core RC2 ■ https://docs.asp.net/en/latest/ ■ https://blogs.msdn.microsoft.com/webdev/
  • 7. Runtime platforms ■ Classical .Net Framework.As always, it can be run on windows. ■ .Net Core.This is cross-platform environment officially developed and supported by Microsoft.Can be installed on windows, linux and Mac. ■ Mono.This is open-source cross-platform port of .NET Framework for non-windows systems. It is not officially supported by Microsoft and probably slower than .Net Core.
  • 8. Web application ■ No more XML configuration, configuration now in JSON ■ Project.json as common project definition file ■ Startup.cs as entry point of application ■ Microsoft.AspNet.Server.Kestrel as running web server ■ All usings are Nuget packages ■ No more required csproj file, all files will be included in build ■ Web application = self-hostable console-application
  • 9. Project.json { "version": "1.0.0-*", "compilationOptions": { "emitEntryPoint": true }, "dependencies": { "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final", "Microsoft.AspNet.Mvc": "6.0.0-rc1-final", "Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-rc1-final", "Microsoft.Extensions.Logging": "1.0.0-rc1-final", "Microsoft.Extensions.Caching.Abstractions": "1.0.0-rc1-final", "Microsoft.Extensions.Caching.Memory": "1.0.0-rc1-final", "System.Console": "4.0.0-beta-23516", "System.Linq": "4.0.1-beta-23516", "Trkd.Dnx.Proxy": "1.0.0-*", "ActiveMashups.Core": "1.0.0-*", "System.Runtime": "4.0.21-beta-23516", "System.Collections": "4.0.11-beta-23516", "System.Linq.Queryable": "4.0.1-beta-23516", "System.Linq.Parallel": "4.0.1-beta-23516", "System.Threading.Tasks": "4.0.11-beta-23516", "System.Runtime.Serialization.Primitives": "4.1.0-beta-23516“ }, "commands": { "web": "Microsoft.AspNet.Server.Kestrel" }, "frameworks": { "dnxcore50": { } }, "exclude": [ "wwwroot", "node_modules" ], "publishExclude": [ "**.user", "**.vspscc" ], "scripts": { "postpublish": "%project:Directory%/postpublish/postpublish.bat" } } "frameworks": { "dnxcore50": { // .Net Core }, "dnx461" :{ // mono }, "net461" :{ // .Net Framework } }
  • 10. Many platforms in-time development
  • 11.
  • 12. Startup.cs public class Startup { public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) { // Set up configuration sources. var builder = new ConfigurationBuilder().AddJsonFile("Configuration/AppSettings.json").AddEnvironmentVariables(); this.Configuration = builder.Build(); } public IConfigurationRoot Configuration { get; set; } public static void Main(string[] args) => WebApplication.Run<Startup>(args); // 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.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseStaticFiles(); app.UseMvc(); } } Configuration loading Services, filters, options, dependency injection, etc Logging, middleware, routing
  • 13. Configuration loading public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) { // Set up configuration sources. var builder = new ConfigurationBuilder() .AddJsonFile("Configuration/AppSettings.json") .AddJsonFile("Configuration/AmqpLoggingSettings.json") .AddEnvironmentVariables(); this.Configuration = builder.Build(); this.Configuration["WebRootPath"] = env.WebRootPath; this.Configuration["AppRootPath"] = appEnv.ApplicationBasePath; } RC1 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(); } RC2
  • 14. Services, filters, options, dependency injection… // 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.AddMvc( mvcOptions => { mvcOptions.Filters.Add(typeof(GlobalExceptionInterseptor)); mvcOptions.Filters.Add(typeof(JsonWebTokenAuthentification)); }); ConfigureOptions(services); ConfigureDependencyInjection(services); }
  • 15. Request filter public class JsonWebTokenAuthentification : ActionFilterAttribute { public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { // if AllowAnonymous attribute is present - skip other checks if (context.Filters.OfType<AllowAnonymousFilter>().Any()) { await next(); return; } else { context.Result = new HttpUnauthorizedResult(); return; } }
  • 16. Options model – load configuration https://docs.asp.net/en/latest/fundamentals/configuration.html#using-options-and-configuration-objects { "AmqpLoggerConfiguration": { "ServerAddress": "http://localhost:15672", "UserName": "guest", "Password": "guest", "VirtualHost": "%2f", "ExchangeName": "gelf.fanout", "Facility": “MyApplication" } } AmqpLoggingSettings.json public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) { // Set up configuration sources. var builder = new ConfigurationBuilder() .AddJsonFile("Configuration/AppSettings.json") .AddJsonFile("Configuration/AmqpLoggingSettings.json") .AddEnvironmentVariables(); this.Configuration = builder.Build();
  • 17. Options model – bind to classes throught DI public class AmqpLoggerOptions { public string ServerAddress { get; set; } public string UserName { get; set; } public string Password { get; set; } public string VirtualHost { get; set; } public string ExchangeName { get; set; } public string Facility { get; set; } } public void ConfigureServices(IServiceCollection services) { services.AddOptions(); services.Configure<AmqpLoggerOptions>(Configuration.GetSection("AmqpLoggerConfiguration")); } Startup.cs
  • 18. public class AmqpLogger : ILogger { private readonly RabbitMqLogger logger; private readonly AmqpLoggerOptions amqpOptions; public AmqpLogger(IOptions<AmqpLoggerOptions> options) { amqpOptions = options.Value; var rabbitOptions = Mapper.Map<RabbitMqLoggerOptions>(amqpOptions); logger = new RabbitMqLogger(rabbitOptions); } public async Task<Guid> LogAsync(IActiveMashupsLogEntry logEntry) { var logMessage = CreateMessageWithDefaultFields(logEntry); var loggingSucceed = await logger.LogMessage(logMessage); if (!loggingSucceed) { throw new Exception("Failed to send logs to amqp"); } return logMessage.Id; } Options model - usage Build-in DI
  • 19. Build-in Dependency Injection https://docs.asp.net/en/latest/fundamentals/dependency-injection.html public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc( mvcOptions => { mvcOptions.Filters.Add(typeof(GlobalExceptionInterseptor)); mvcOptions.Filters.Add(typeof(JsonWebTokenAuthentification)); }); ConfigureOptions(services); services.AddSingleton<AmqpLogger>(); services.AddSingleton<FileLogger>(); services.AddTransient<ILogger, AmqpAndFileLogger>(); services.AddSingleton<ITokensManager, TrkdTokensManager>(); } Startup.cs
  • 20. Dependency Injection - Service Lifetimes ASP.NET services can be configured with the following lifetimes: ■ Transient - Transient lifetime services are created each time they are requested. This lifetime works best for lightweight, stateless services. ■ Scoped - Scoped lifetime services are created once per request. ■ Singleton - Singleton lifetime services are created the first time they are requested (or when ConfigureServices 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.
  • 21. Logging, middleware, routing // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseMiddleware<LogBadResponsesAsWarningsMiddleware>(); app.UseMiddleware<ContentLengthResponseHeaderWriterMiddleware>(); app.UseStaticFiles(); app.UseMvc(routes => { // add the new route here. routes.MapRoute(name: "areaRoute", template: "{area:exists}/{controller}/{action}/{id?}", defaults: new { controller = "Home", action = "Index" }); }); } Startup.cs
  • 22. Middleware (ex HTTP Module) https://docs.asp.net/en/latest/fundamentals/middleware.html
  • 23. Middleware example public class ContentLengthResponseHeaderWriterMiddleware { private readonly RequestDelegate next; public ContentLengthResponseHeaderWriter(RequestDelegate next) { this.next = next; } public async Task Invoke(HttpContext context) { using (var buffer = new MemoryStream()) { var response = context.Response; var bodyStream = response.Body; response.Body = buffer; await this.next(context); var lenght = buffer.Length; if (lenght > 0) { response.Headers.Add("Content-Length", new[] { lenght.ToString() }); } buffer.Position = 0; await buffer.CopyToAsync(bodyStream); } } }
  • 24. United controller [Area("Portfolios")] [Route("[controller]")] public class PortfoliosController : Controller { public async Task<object> Get() { return await new GetPortfoliosWorkflow(this.HttpContext).ExecuteAsync(null); } [HttpGet("{portfolioId}")] public async Task<object> Get(long portfolioId) { return await new GetSinglePortfolioWorkflow(this.HttpContext).ExecuteAsync(portfolioId); } [HttpPost] public async Task<object> Post([FromBody]PortfolioViewModel portfolioViewModel) { var result = await new CreatePortfolioWorkflow(this.HttpContext).ExecuteAsync(portfolioViewModel); var locationHeader = HttpContext.Request.GetDisplayUrl() + "/" + result.PortfolioId; return Created(locationHeader, result); } [HttpPut("{portfolioId}")] public async Task<object> Put(long portfolioId, [FromBody]PortfolioViewModel portfolioViewModel) { if (portfolioViewModel.PortfolioId != 0 && portfolioViewModel.PortfolioId != portfolioId) { return new BadRequestObjectResult("Portfolio id from url is not equal to portfolio id from request"); } portfolioViewModel.PortfolioId = portfolioId; return await new UpdatePortfolioWorkflow(this.HttpContext).ExecuteAsync(portfolioViewModel); }
  • 25. Kestrel ■ Kestrel is a cross-platform web server based on libuv, a cross-platform asynchronous I/O library. ■ You add support for Kestrel by including Microsoft.AspNet.Server.Kestrel in your project’s dependencies listed in project.json. ■ https://github.com/aspnet/KestrelHttpServer https://docs.asp.net/en/latest/fundamentals/servers.html
  • 26. CLITools ■ The DNX Utility (DNU) tool is responsible for all operations involved with packages in your application. ■ Dotnet version manager (DNVM) is responsible for downloading and installation environment runtimes. ■ DNX is .NET Execution Environment that will execute your application.
  • 27. Dotnet version manager (DNVM) You can install any environment that is available on platform you are using. Some useful cli commands: ■ dnvm list - will show you list of available installer runtimes, their aliases and current default runtime (marked by *) ■ dnvm install - installs requested runtime (example - dnvm install latest -r coreclr -acrh x64) ■ dnvm use - selects specific runtime as default (examples - dnvm use default; dnvm use 1.0.0-rc1-update1 -r coreclr -acrh x64)
  • 28.
  • 29. The DNX Utility (DNU) ■ DNU restore - restores nuget pakages ■ DNU publish - will package your application into a self-contained directory that can be launched. It will create the following directory structure output/ output/packages output/appName output/commandName.cmd Note, that DNU can be unavailable if there is no runtime selected in DNVM (even if runtimes are installed).
  • 30. .NET Execution Environment (DNX) In common case it's only used to run you app by execution from directory with project.json file: ■ dnx web - for web app ■ dnx run - for console app
  • 31. CLI tools from RC 1 to RC 2 DNVM, DNU, DNX = > Dotnet DNX command CLI command Description dnx run dotnet run Run code from source. dnu build dotnet build Build an IL binary of your code. dnu pack dotnet pack Package up a NuGet package of your code. dnx [command] (for example, "dnx web") N/A* In DNX world, run a command as defined in the project.json. dnu install N/A* In the DNX world, install a package as a dependency. dnu restore dotnet restore Restore dependencies specified in your project.json. dnu publish dotnet publish Publish your application for deployment in one of the three forms (portable, portable with native and standalone). dnu wrap N/A* In DNX world, wrap a project.json in csproj. dnu commands N/A* In DNX world, manage the globally installed commands. (*) - these features are not supported in the CLI by design.
  • 32. Known issues ■ Kestrel do not set content-length header in response. If your component needs this header (for example, java-based vert.x uses content-length to read message body), add middleware as workaround. ■ While working with 3rd party datasources, especially withWCF SOAP (IIS) services, server can send response with GZipped content + content-length (header) of GZipped body. System libs fails to deserialize response body, they UZipping body, but reads it using content-length header of GZipped body. Thus, body can be read only by half of its contents.
  • 33. RC2, RTM and future
  • 35. Thanks! MAKSIM VOLK Software Engineer Office: +375 17 389 0100 x 40673 Cell: +375 29 365 6597 Email: maksim_volk@epam.com Minsk, Belarus (GMT+3) epam.com