Skip to content

Tutorial 1: Step 1: Quick Northwind sample.

cdmdotnet edited this page Feb 1, 2018 · 5 revisions

This tutorial utilises the the popular Northwind database (https://www.microsoft.com/en-us/download/details.aspx?id=23654). We start off with an existing sample (taken from Telerik), then systematically we'll replace the entity framework back-end (this is not focusing at all on the front end) with a CQRS.NET scalable back-end.

Shortcut

If you'd rather just get the code, jump straight into our code base for a complete working copy... just enter the connection strings that match your local setup.

1. Download the Northwind Dashboard

  1. Download the Telerik Northwind Dashboard from (https://github.com/telerik/kendoui-northwind-dashboard) then open the solution file at \aspnet-mvc\kendoui-northwind-dashboard.sln
  2. Compile and run the website. If no charts display or you get a No data available message, check the web.config connection string settings for entity framework and correct them as necessary. You may also need to enable the relevant MIME types for json files by adding the following to the web.config file:

<!-- XML -->

<system.webServer>
	<staticContent>
		<mimeMap fileExtension=".json" mimeType="application/json" />
	</staticContent>
</system.webServer>
  1. Navigate to PRODUCTS & ORDERS. a grid of orders should be displayed. Again check your settings if the website fails to load any data.

2. Add CQRS.NET

  1. Upgrade the project from .net 4.0 to .net 4.5

  2. Upgrade the Newtonsoft.Json nuget package

  3. Add the Cqrs.Ninject.WebApi nuget package

  4. Close and re-open the solution to update MVC / WebAPI

  5. In global.asax.cs, replace the inherited class of HttpApplication with CqrsHttpApplicationWithSignalR <string> (This was CqrsHttpApplication<string, EventToHubProxy> prior to version 2.2) and set the following namespace:

5.1

  • using Cqrs.WebApi;

5.2 Prior to version 2.2, also add:

  • using Cqrs.Ninject.Configuration;
  • using HelloWorld.Code;
  1. Remove the existing Application_Start method and add the follow to Global.asax.cs.

6.1 Prior to version 2.2:

// C#

protected override void ConfigureDefaultDependencyResolver()
{
	DependencyResolver = NinjectDependencyResolver.Current;
}

protected override void ConfigureMvc()
{
	AreaRegistration.RegisterAllAreas();
	GlobalConfiguration.Configure(WebApiConfig.Register);
	FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
	RouteConfig.RegisterRoutes(RouteTable.Routes);
	BundleConfig.RegisterBundles(BundleTable.Bundles);
}

6.2 Version 2.2 or newer:

// C#

protected override void ConfigureMvcOrWebApi()
{
	AreaRegistration.RegisterAllAreas();
	GlobalConfiguration.Configure(WebApiConfig.Register);
	FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
	RouteConfig.RegisterRoutes(RouteTable.Routes);
	BundleConfig.RegisterBundles(BundleTable.Bundles);
}

protected override void RegisterSignalR(Cqrs.Configuration.BusRegistrar registrar)
{
	// Not yet needed.
}

protected override void StartBuses()
{
	// Not yet needed.
}
  1. Remove the now auto added file \App_Start\NinjectWebCommon.cs

  2. Add the following app setting:

<add key="Cqrs.WebApi.AuthenticationTokenType" value="string" />

  1. Add a new class to the App_Start folder as follows:

// C#

[assembly: Microsoft.Owin.OwinStartup(typeof(KendoUI.Northwind.Dashboard.Startup))]

namespace KendoUI.Northwind.Dashboard
{
	using Owin;

	public partial class Startup
	{
		public void Configuration(IAppBuilder app)
		{
		}
	}
}
  1. Add the following to the top of the web.config file

<!-- XML -->

<configSections>
	<section name="LoggerSettings" type="cdmdotnet.Logging.Configuration.LoggerSettingsConfigurationSection, cdmdotnet.Logging" />
</configSections>
<LoggerSettings EnableInfo="false" EnableDebug="false" EnableProgress="false" EnableWarning="true" EnableError="true" EnableFatalError="true" EnableSensitive="false" EnableThreadedLogging="true" ModuleName="MyCompany" Instance="MyApplication" EnvironmentInstance="Server1" Environment="Production" EnableThreadedLoggingOutput="false" UsePerformanceCounters="false" UseApplicationInsightTelemetryHelper="false" SqlDatabaseLogsConnectionStringName="Logging" SqlDatabaseTableName="Logs" />
  1. Compile and run the site.

Tutorial 1 Step 2

You have now added and configured CQRS.NET into an existing website. Your code is now ready for step 2, where we will replace a query that uses EntityFramework with CQRS.NET queries.

Clone this wiki locally