Angular Constants Injected Server Side from ASP.NET CSHTML

Most answers on the internet work well for JIT compilation, refer to the stack overflow article here;  Stack Overflow Question

We are using JIT compilation for development and AOT for deployment. I couldn’t find a good way to make the standard approach work with AOT. For reference I followed the AOT cookbook here… Angular AOT cookbook.

The approach below will not work for server side rendering but should suffice for both JIT and AOT client side rendering.

1) In the razor view, _layout.cshtml for example, just put a script block and set a JSON object on the window interface. I placed this block within the “head” tag but doesn’t really matter. The values for the JSON keys can be determined by any razor syntax.

[code language=”javascript”]
window.appContext = {
userName: ‘@("test".ToUpper())’,
isAdmin: @(1 == 1 ? "true" : "false")
};
[/code]

2) Create an app context service and wire up in appropriate module and inject into components for usage, if you need help with this just comment and I’ll supply more info.

[code language=”javascript”]
import { Injectable } from ‘@angular/core’;

/*
must match definition in SCRIPT tag that is seeded from razor
*/
interface IAppContext {
userName: string;

isAdmin: boolean;
}

/*

*/
@Injectable()
export class AppContextService implements IAppContext {

userName: string;

isAdmin: boolean;

constructor() {
var appContextBootstrap: IAppContext = (<IAppContext>(<any>window).appContext);

this.userName = appContextBootstrap.userName;
this.isAdmin = appContextBootstrap.isAdmin;
}

}
[/code]

3) reference and use the app context service throughout the application.

[code language=”javascript”]
import { Component } from ‘@angular/core’;

import { AppContextService } from ‘./appContext.service’

@Component({
moduleId: module.id,
selector: ‘story-app’,
templateUrl: ‘app.component.html’
})
export class AppComponent {
AppConfig: any;
constructor(private appContext: AppContextService) { }

ngOnInit() {

alert(‘hi – ‘ + this.appContext.userName);
}
}
[/code]

Planning and Events Product

In 2017, EmpireCLS wanted to simplify the management of events. An event was a large number of people being driven to and from venues. A venue would be for as little as a single day or up to several days or weeks long. This was an extremely manual process and required many staff hours to manage and validate.

We developed the entire MVP using a “no DB” approach. In order to cut down on the friction of any type of database we used in memory repositories to track all data. A generic set of classes were used to manage the memory repository and offered simple migration to full DB support. We used domain models from the repositories as the application view of data, the repositories would then map the domain models into whatever storage we wanted; mongo, SQL, etc.

We used Typewriter to generate our client typescript code based upon the web API interface, API models, and domain models. By authoring a few templates in Typewriter we would have all of the client-side Angular HTTP services, DTO’s, and view models generated for us. This streamlined the development process immensely.

Technologies… C#, asp.net MVC, asp.net Web API, Angular, Typewriter

On Demand Product

In 2016, EmpireCLS wanted to build a new product to tackle on-demand for the corporate customer. This product was to have a no-touch integration with their 400+ affiliate network and provide real-time availability of inventory through the EmpireCLS customer app.

We developed the entire MVP using a “no DB” approach. In order to cut down on the friction of any type of database we used in memory repositories to track all data. A generic set of classes were used to manage the memory repository and offered simple migration to full DB support. We used domain models from the repositories as the application view of data, the repositories would then map the domain models into whatever storage we wanted; mongo, SQL, etc.

We used Typewriter to generate our client typescript code based upon the web API interface, API models, and domain models. By authoring a few templates in Typewriter we would have all of the client-side Angular HTTP services, DTO’s, and view models generated for us. This streamlined the development process immensely.

The project was put on hold indefinitely after a simplified POC was delivered to the executive team.

Technologies… C#, asp.net MVC, asp.net Web API, AngularJS, Typewriter

Logical Locking Software

In 2015, EmpireCLS needed a way to alleviate the physical locking issues that they were facing when users edited a reservation. The legacy Linux system was using a physical database lock that would stay active when a user attempted to edit a reservation, this lock would remain in effect until the user explicitly released it or their process was killed by an admin. Because killing the process became the normal procedure the user that had the lock would lose any in process edits. This problem directly impacted daily operations, automated booking feeds, and the IT staff.

We built a cross platform logical locking framework that would enforce the same edit semantics that the EmpireCLS staff had grown accustomed to but would allow supervisors to release locks without the need of killing a process and losing the in process changes for a user.

This implementation required both a Linux and Windows code base so we used C# / Mono to create the cross platform libraries.

Technologies… C#, C, Linux, asp.net, Mono

GPS Tracking Software

In 2014, EmpireCLS needed a better GPS solution to track all of its vehicles. This service was a direct dependency of the “auto dispatch” system.

We ended up writing GPS query services to both Bing and Google. Cost was a constant factor as the number of queries that needed to be made was in the 100’s of thousands a day.

Technologies… C#, Google API

Suggestive Dispatch Software

In 2014, EmpireCLS wanted to optimize their dispatch department by automating the chauffeur to reservation assignments that they have been manually doing for decades.

Building on the rules of the newly created dispatch application this application would attempt to automate as much of the work as possible. Some of the rules that would need to be taken into consideration are as follows; driver requests by customer, driver location to customer, VIP customer handling, where driver started their day, shift time, etc.

A real-time GPS tracking system was also required for this system so as to have constant visibility to driver location and time / duration to a customer location or when the customer would be dropped off.

We ended up treating output of the system as suggestions that the dispatcher could just accept as opposed to 100% automation. There were edge cases that could not be covered for 100% automation so suggesting vs. automating was the better solution.

A dispatcher using this tool was able to assign all of the work for the first shift drivers in seconds, where previously it took over an hour.

Technologies… C#, asp.net MVC, Mongo, SQL Server

Promotion Software

In 2013, EmpireCLS needed the ability to offer promotions to their customers. The current method of just crediting their account after the fact didn’t allow them the marketing flexibility that they were looking for.

We designed and implemented the system that would allow EmpireCLS to have time based, instance based, and customer based promotions.

Once the project was completed the marketing team had the tools to create promotions which would allow EmpireCLS to offer services during low volume times, lure back customers that didn’t use the service for a while, and bring on new customers that never heard of them before.

Customer Booking App

C# development using Xamarin for IOS for a customer app. This app allows customers to book, view, and cancel their reservations, shows real-time ETA and location of vehicle driving towards the pickup location, and offers visibility into receipts and billing information.

Technologies… Xamarin, asp.net web API, SQL Server, Linux, IOS

Chauffeur App 2.0

In 2013, EmpireCLS needed to revamp their mobile chauffeur application because the Windows Mobile 6 platform was to be deprecated. Windows Phone 8 was the platform of choice for this application that supported their 400+ mobile workforce.

A large amount of client code was re-used from the original mobile app, along with the entire back end.

Highlights…

  • Chauffeurs could notify central dispatch that they were awake and ready for work. Before this feature dispatchers would call chauffeurs on the phone to validate that they were ready and would make their first pickup of the day. This saved thousands of man-hours a year.
  • Was done using cross platform development patterns to allow other mobile platforms to be implemented. The goal of using Xamarin to create an IOS an Android app was taken into consideration way up front to cut down on overall cost of bringing up these 2 platforms at a later date.

Technologies… Windows Phone 8, c#, WCF, PCL