Take advantage of the unified programming model in ASP.Net 5 MVC 6 to build applications that are cloud optimized The Model View Controller pattern is one of the most popular design patterns that helps you to build applications that are easier to test and maintain. The Model View Controller (commonly known as MVC) framework promotes easier testability and code re-use. The ASP.Net MVC framework is built on top of the ASP.Net runtime and follows the MVC design pattern. In this post I will examine the Model View Controller design pattern and also present an overview of the new features in ASP.Net MVC 6. The Model View Controller design pattern as the name suggests, comprises of three major components. These include the following: Model — this is the layer that represents the application’s data View — this represents the presentation or the user interface layer Controller — this layer typically contains the business logic of your application The Model View Controller design pattern enables you to isolate the concerns and makes your application’s code easier to test and maintain. The latest version of this framework is MVC 6. With MVC 6 the dependency on System.Web.dll has been eliminated — you will need to include the Microsoft.AspNet.Mvc namespace unlike System.Web.Mvc you did in the previous versions of ASP.Net MVC framework. The dependency on System.Web has been removed as it was very expensive — MVC 6 provides you a much leaner framework, faster startup time and reduced resource consumption. The MVC 6 framework is designed for the cloud and is incorporated as part of the cloud optimized ASP.Net 5 runtime which in turn would be available as part of Visual Studio 2015. The advantage of having a cloud optimized framework is that you can have different versions of the CLR reside side by side for different websites running in the cloud. With ASP.Net 5, the MVC and Web API frameworks have been unified into a single programming model. So, MVC, Web API and the ASP.Net runtime are now all merged into one unified programming model. MVC 6 is host agnostic — other than having the capability to be hosted on IIS, it can be self-hosted also. MVC 6 also provides support for OWIN abstraction and includes Web API and Web Pages to eliminate the overlap between these three frameworks. Dependency injection (also known as Inversion of Control) is a software design pattern that is used to implement loosely coupled, testable and reusable objects in your application. You can leverage the IServiceProvider interface to add your custom dependency injection container. This interface provides a level of abstraction over the actual dependency injection container implementation. Note that you have a default dependency injection container but with limited functionality. You can use this default dependency injection container if you need limited functionality. If you need added functionality, you can build your own dependency injection container and use the IServiceProvider interface to add the custom dependency injection container you have created. Unlike its earlier counterparts, MVC 6 supports an environment based configuration system — deploying MVC 6 applications in the cloud is now simple. When you create a new MVC 6 project in Visual Studio, the new set of configuration files you would observe include the following: Config.json — this would typically contain the application configuration Project.json — this file contains the project dependency information Startup.cs — this file contains the Startup class that in turn contains a Configure method Global.json — this file contains information on the project references After you create a MVC 6 project in Visual Studio, the Startup.cs file looks like this: using Microsoft.Owin; using Owin; [assembly: OwinStartupAttribute(typeof(IDG.Startup))] namespace IDG { public partial class Startup { public void Configuration(IAppBuilder app) { } } } The following code snippet illustrates how a typical Config method of the Startup class looks like. public void Configure(IApplicationBuilder app) { var configuration = new Configuration().AddJsonFile(“config.json”).AddEnvironmentVariables(); } Note the IApplicationBuilder parameter (this parameter is passed by the host when the application is started) in the Configure method. An instance of Configuration class is created and the configuration sources are passed. You can have any number of configuration sources — each configuration source is associated with a configuration value provider. This approach facilitates moving your application to the cloud if need be, seamlessly. You can also use the ConfigureServices method to add Entity Framework services to the services container. The following code snippet shows how a typical ConfigureServices method would look like. public void ConfigureServices(IServiceCollection services) { services.AddEntityFramework().AddSqlServer().AddDbContext(); services.AddMvc(); //Other code } You can also specify the route information using the UseMvc extension method as shown in the code snippet below. { routes.MapRoute( name: “default”, template: “{controller}/{action}/{id}”, defaults: new { controller = “IDG”, action = “Index” }); Note that the AddEntityFramework() and AddMvc() are extension methods defined in the IServiceCollection interface. I will write more articles on MVC 6 in my future blog posts here. So, stay tuned! Related content feature What is Rust? Safe, fast, and easy software development Unlike most programming languages, Rust doesn't make you choose between speed, safety, and ease of use. Find out how Rust delivers better code with fewer compromises, and a few downsides to consider before learning Rust. By Serdar Yegulalp Nov 20, 2024 11 mins Rust Programming Languages Software Development how-to Kotlin for Java developers: Classes and coroutines Kotlin was designed to bring more flexibility and flow to programming in the JVM. Here's an in-depth look at how Kotlin makes working with classes and objects easier and introduces coroutines to modernize concurrency. By Matthew Tyson Nov 20, 2024 9 mins Java Kotlin Programming Languages analysis Azure AI Foundry tools for changes in AI applications Microsoft’s launch of Azure AI Foundry at Ignite 2024 signals a welcome shift from chatbots to agents and to using AI for business process automation. By Simon Bisson Nov 20, 2024 7 mins Microsoft Azure Generative AI Development Tools news Microsoft unveils imaging APIs for Windows Copilot Runtime Generative AI-backed APIs will allow developers to build image super resolution, image segmentation, object erase, and OCR capabilities into Windows applications. By Paul Krill Nov 19, 2024 2 mins Generative AI APIs Development Libraries and Frameworks Resources Videos