In this article I will
explain in detail latest Asp.net 5 preview release.Asp.net era started with
first preview release ASP.NET 1.0 around 15 years ago, millions of developers
have used it to build and run web applications, and over the years Microsoft
added great features in asp.net.
ASP.NET 5:
ASP.NET 5 is a
significant change of ASP.NET, in this article I will introduce you asp.net 5
purviews.
ASP.NET 5 is a new open-source and cross-platform framework for building modern
cloud-based Web apps. using .NET.
You can develop and run your ASP.NET 5 applications cross-platform on Windows,
Mac and Linux.
Asp.net open source code is available in GitHub.
Some new
features with asp.net 5:
1. New
light-weight and modular HTTP request pipeline
2. Ability to host
on IIS or self-host in your own process
3. Built on .NET
Core, which supports true side-by-side app versioning
4. Ships entirely
as NuGet packages
5. Integrated
support for creating and using NuGet packages
6. Single aligned
web stack for Web UI and Web APIs
7. Cloud-ready
environment-based configuration
8. Built-in
support for dependency injection
9. New tooling
that simplifies modern web development
10. Build and run
cross-platform ASP.NET apps on Windows, Mac and Linux
12. Open source and
community focused
.NET Execution Environment
(DNX):
ASP.NET 5/DNX is a lean
.NET stack for building modern cloud and web apps that run on OS X, Linux, and
Windows.
Microsoft team making number of changes of architectural changes that makes the
core web framework much leaner (it no longer requires System.Web.dll).
SP.NET 5 applications are built and run using the new .NET Execution
Environment (DNX). Every ASP.NET 5 project is a DNX project.
Every asp.net 5
applications defined using a public start-up class:
Sample example:
public class Startup
{
public void ConfigureServices(IServiceCollection myservices)
{
}
public void Configure(IApplicationBuilder myapp)
{
}
}
ConfigureServices: Method used to
define services used by your application.
Configure: Method used to
define what middleware makes up your request pipeline.
Service:
Service is a component
available through dependency injection. Services in ASP.NET 5 come in three
varieties: singleton, scoped and transient. Transient services are created each
time they’re requested from the container. Scoped services are created only if
they don’t already exist in the current scope. For Web applications, a
container scope is created for each request, so you can think of scoped
services as per request. Singleton services are only ever created once.
Servers:
ASP.NET 5 includes
server support for running on IIS or self-hosting in your own process. You can
use cross platform servers also to host your ASP.NET 5 web application.
Web Root:
The Web root of an
ASP.NET 5 application is configured using the “webroot” property in your
project.json file.
Client-side development:
Asp.net 5 supports or
you can integrate seamlessly with a variety of client-side frameworks like
Bootstrap,AngularJS,KnouckoutJS.
Configuration:
Asp.net 5 new
configuration model is not based on System.Configuration or Web.config. This
new configuration model pulls from an ordered set of configuration providers.
The built-in configuration providers support a variety of file formats (XML,
JSON, INI) and also environment variables to enable environment-based
configuration. You can also write your own custom configuration
providers.

Dictionary Initializer or Index Initializers:
Developer
feels with C# 5.0 or previously syntax for instantiating dictionaries is
complex and confusing.
With C# 6.0
the syntax for creating dictionaries is now more simple and clear. It makes the
code easier to read.
C# 5.0 (VS
2012)
Dictionary<string,string> StudentNames = new Dictionary<string, string>()
{
{ "Nagnath Kendre", "Engineering" },
{ "Sharad Sangle", "arts" },
{ "Girish Sarode", "Commerce" }
};
C# 6.0 (VS 2015)
Dictionary<string,string> StudentNames = new Dictionary<string, string>()
{
["Nagnath Kendre"] = "Engineering",
["Sharad Sangle"]= "arts" ,
["Girish Sarode"] = "Commerce"
};
<

ASYNC IN A CATCH AND FINALLY BLOCK:
In C# 5.0 we
can use try, catch and finally blocks together but was unable to use async and
await with catch {} and finally {} blocks due to implementation specific issues
in the C# compiler.
This is nice feature provided by C# 6.0, you can do some
task without blocking current thread.
Requirement is that create some console application as background process that runs every day and updates data, we require to maintain logs and create notification for exception or failure in that case this new feature is use
full.
Example(only exception code in sample example):
catch (SqlException ex)
{
const
string
errormsg = "Sql exception
encountered.";
await Task.Delay(3000); //waits for 3 seconds
logger.WriteError(errormsg, ex);
SendErrorEmail(errormsg, ErrorEmailSubject);
}
catch
(NullReferenceException ex)
{
const
string
errormsg = "Null reference
exception encountered.";
await
logger.WriteError(errormsg,
ex);
SendErrorEmail(errormsg, ErrorEmailSubject);
}
catch
(ArgumentNullException ex)
{
const
string
errormsg = “Argument null reference
exception encountered.";
await Task.Delay(2000); //waits for 2 seconds
logger.WriteError(errormsg,
ex);
SendErrorEmail(errormsg,
ErrorEmailSubject);
}
finally
{
//here release all
resources
}
< >