-
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.
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.
- 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
withCqrsHttpApplicationWithSignalR <string>
(This wasCqrsHttpApplication<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;
- Remove the existing
Application_Start
method and add the follow toGlobal.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.
}
-
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)
{
}
}
}
- 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" />
- Compile and run the site.
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.