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

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

Tranquility Product

In 2012, EmpireCLS needed to build out their new platform that would replace their existing Linux platform lovingly known as Iliad. We termed the new platform “Tranquility” to try and install a sense of calmness for those migrating from the legacy platform.

The existing linux platform had around 1 million lines of code, over 200 applications, and 20 years of data in an ISAM database. Our goal was to build this new web platform on Windows and slowly migrate the individual programs.

From the onset we counted on running both systems side by side and slowly migrating users to the new system. We chose the side by side approach to cut down on risk to the company, simplify training, and allow real-time validation between systems.

The initial modules that were moved were read-only; customer profiles, reservations, chauffeur HR. New modules were added to support credit card rebills, chauffeur check-ins, system monitoring, and several third party integration portals.

Technologies… C#, asp.net MVC, SQL Server, asp.net web API, Angular, Typescript

Be Transported Product

In 2011, EmpireCLS wanted to unite their 500+ affiliate network and build a marketplace for customers.  This was a brand new business entity and was released as betransported.com.

We worked extensively with the EmpireCLS executive team to help define the business model.  We were then able to implement the entire application in around 9 months; website, accounting, mobile app, and the on boarding of 400+ affiliate partners.

The project was a success as far as the partner relationships were concerned.  There were many challenges with getting customer adoption so it was put on hold indefinitely.

System highlights… web UX for creating rating structures, extensible rating API, cross platform mobile app with code reuse from back end, extensible excel import framework for bulk loading rating structures.

Technologies… C#, SQL Server, asp.net MVC, asp.net Web API, Xamarin.

Chauffeur App

In 2008 EmpireCLS needed to revamp their current pager strategy for communicating reservation information and statuses to and from their chauffeurs. We created a Windows Mobile 6 app to be deployed on Moto Q devices.

Once released the chauffeurs had constant real-time updates of reservations data and had the ability, via 1 or 2 taps, to notify dispatch of various statuses that occur when picking up and driving a customer to their destination.

This project required a backend web service implementation to communicate with the mobile device app. The backend web service in turn communicated with several Linux services via windows sockets.

Technologies… Windows Mobile 6, .net framework, WCF, asp.net, IIS