Skip to content

Tutorial 1: Step 1: Quick Northwind sample.

cdmdotnet edited this page Jun 21, 2017 · 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.

To start:

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 CqrsHttpApplication<string, EventToHubProxy<string>> and set the following namespaces:

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

// C#

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

protected override void ConfigureMvc()
{
	AreaRegistration.RegisterAllAreas();

	RegisterGlobalFilters(GlobalFilters.Filters);
	RegisterRoutes(RouteTable.Routes);
}
  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. Compile and run the site.

3 Added

Add System.Data.Linq assembly Add Order entity class Add IDomainDataStoreFactory Add DomainDataStoreFactory Add IOrderRepository Add OrderRepository Add OrderQueryStrategy

Add to global.asax.cs

	protected override void Application_BeginRequest(object sender, EventArgs e)
	{
		try
		{
			ICorrelationIdHelper correlationIdHelper = NinjectDependencyResolver.Current.Resolve<ICorrelationIdHelper>();
			correlationIdHelper.SetCorrelationId(Guid.NewGuid());
		}
		catch (NullReferenceException) { }
	}

Step 4.4

  • NorthwindModule
  • NorthwindConfiguration Add appsetting and connection string for SQL data store Run Sql to update Northwind Update OrderController

NOW CREATE

change app setting Add created order event Add order aggregate - Add create method Add create order command Add create order command handler Add created order event handlers Step 4.1, 4.2 and 4.3 Modify existing 4.4 Update OrdersController > Orders_Create Update global.asax.cs protected override BusRegistrar RegisterCommandAndEventHandlers() { BusRegistrar registrar = base.RegisterCommandAndEventHandlers(); registrar.Register(typeof(Order)); return registrar; }

NOW UPDATE

Add updated order event Update order aggregate - Add update method Add update order command Add update order command handler Add updated order event handlers

NOW DELETE

Add deleted order event Update order aggregate - Add delete method Add delete order command Add delete order command handler Add deleted order event handlers

Clone this wiki locally