-
Notifications
You must be signed in to change notification settings - Fork 79
Tutorial 1: Step 1: Quick Northwind sample.
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:
- 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
- Compile and run the website. If no charts display or you get a
No data available
message, check theweb.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 theweb.config
file:
<!-- XML -->
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
- Navigate to
PRODUCTS & ORDERS
. a grid of orders should be displayed. Again check your settings if the website fails to load any data.
-
Upgrade the project from .net 4.0 to .net 4.5
-
Upgrade the
Newtonsoft.Json
nuget package -
Add the
Cqrs.Ninject.WebApi
nuget package -
Close and re-open the solution to update MVC / WebAPI
-
In
global.asax.cs
, replace the inherited class ofHttpApplication
withCqrsHttpApplication<string, EventToHubProxy<string>>
and set the following namespaces:
using Cqrs.Ninject.Configuration;
using Cqrs.WebApi;
using Cqrs.WebApi.Events.Handlers;
- Remove the existing
Application_Start
method and add the follow toGlobal.asax.cs
.
// C#
protected override void ConfigureDefaultDependencyResolver()
{
DependencyResolver = NinjectDependencyResolver.Current;
}
protected override void ConfigureMvc()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
-
Remove the now auto added file
\App_Start\NinjectWebCommon.cs
-
Add the following app setting:
<add key="Cqrs.WebApi.AuthenticationTokenType" value="string" />
- 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)
{
}
}
}
- Compile and run the site.
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