Skip to content

Configuring ASP.NET MVC → Web API → SQL Server

Aaron Hanusa edited this page Jan 24, 2016 · 5 revisions

ASP.NET MVC → Web API → SQL Server

MVC → APS → SQL Server

Watch the configuration video here.

In this scenario, the ASP.NET MVC client consumes business services that are injected with data proxies that use HTTP (via HttpClient) to communicate with the Web API application. In turn, the Web API application uses business services that are injected with data proxies that use Entity Framework 6.0 to communicate with a SQL Server database.

The MVC project uses dynamic dependency injection to create business services and data proxies that will be injected into the MVC controllers. To configure the MVC project to consume Entity Framework data proxies, open the DependencyInjection.config file.

Notice that there are three configuration sections for data proxies; Entity Framework, HTTP, and In-Memory, respectively. Ensure that the HTTP Data Proxies section is uncommented and the others are commented out.

Also notice that there are two configuration sections for business services; MVC and Web API, respectively. Ensure that the Business Services - Web API section is uncommented and the Business Services - MVC section is commented out.

An important thing to note is that the Business Services - Web API section in the configuration file uses two business services that can be referred to as client service proxy classes. Let's take a look at the config section:

MVC-Config

The classes highlighted in red represent client service proxy classes. These classes inherit from other service classes and override command methods to bypass any command logic to simply marshal calls to the data proxy. To learn more about the necessity of client service proxies, see using client service proxies.

The next step is to configure the Web API project. The Web API project uses dynamic dependency injection to create business services and data proxies that will be injected into the API controllers. To configure the Web API project to consume in-memory data proxies, open the DependencyInjection.config file.

Notice that there are two configuration sections for data proxies; one for Entity Framework and one for In-Memory, respectively. Simply ensure that the Entity Framework Data Proxies section is uncommented and the In Memory Data Proxies section is commented out.

Before running the application, be sure to setup SQL Server after changing the configuration.

To run the application, set the WPF and Web Api projects as the startup projects in the solution and run the application.