CategoryGit

Building an Angular 2 + Typescript application template

Last time I showed you a way to create a Typescript application template. Now we can use that as a starting point for an Angular 2 application.

As usual, I have created a GitHub repo with the necessary sources and the list of steps to perform. At the end of the process, we’ll get our friendly web server showing a nice “lorem ipsum” coming from an Angular2 Component .

Also in this case the core of the system is gulpfile.js which exposes a bunch of tasks:

  1. ‘clean’ : as the name may suggest, this task is used to clear the www folder from all the external libraries, the transpiled .js files and sourcemaps
  2. ‘libs’: this will copy the depencencies to a specific folder
  3. ‘build’: this will execute ‘clean’ and ‘libs’ and then transpile the .ts files
  4. ‘default’: will execute ‘build’, fire up the webserver and watch the .ts files for changes

Worth of mention is also the index.html which contains the SystemJs initialization code.

Enjoy!

How to setup your environment to write Typescript client applications

Hi all! This time I thought it could be useful to write down a couple of notes about how to setup your development environment ( in my case the wonderful Visual Studio Code on Mac ) and start writing Typescript applications.
To be honest I am writing this only because my memory is becoming sloppy and I am getting lazier day after day 😀

I created a repo on GitHub with the list of steps to perform and an example project.

In a nutshell you have to:
1) create the project folder
2) install a bunch of npm packages globally and locally
3) initialize your project with npm init
4) start coding 🙂

You will find all the details in the Readme.md.

At the end of the process your dev environment will be configured to watch the /src/ folder for changes on .ts files, transpile them into Javascript and run a small web server.

Enjoy!

CQRS: on Commands and Validation part 2: the base handler

Last time we discussed how to use the Decorator pattern to validate our Commands. The approach works fine but while using it I started feeling something strange. It can be probably considered an elegant solution but there’s something missing, like a code smell.

What is the problem? Easy: how can you tell if you are really running the validation? What if you just “forget” to register the decorator? Nah, you need it.

Also, a better use for decorators should be all those cross cutting concerns like logging, tracing and so on.

Another very simple solution is to use a base class for the Command Handlers that takes an instance of IValidator as optional dependency and consumes it right before executing the command:

as you can see in this case the validator returns a “result” object that exposes a boolean status flag and a list of errors that may have occurred.
If the validation fails a specific exception is thrown, containing the list of errors.

If instead everything is ok, the protected method RunCommand() is executed, and that’s the only thing you have to implement in your Command Handlers 🙂

Dell Limerick Hackathon 2016

Hi everybody!

Last January we had an Hackathon here @ Dell Limerick, the main theme was “office productivity”, aka “how would you improve your and your coworker’s productivity”.

I was in a team with other 4 very smart guys, didn’t won but all in all it was a terrific experience…two days straight of brainstorming and coding madness combined with pizza and energy drinks.

The winners came up with an interesting prototype of a chat bot running as Lync addon that can answer every type of question, from “how’s the weather” to “who broke the last build?”, passing from “tell me about story 1234567”. I can’t go too deep in the details (also, lots of natural language analysis is involved) but it was definitely a very, very interesting project and really deserved to win.

My team instead…well we produced a voting platform for ideas. In a nutshell, every user registered to the community can post his ideas (which can be divided into macro-areas) and the others can vote it using points they have received when registering. If an idea is approved, the voters will get back the points and a small bonus. If an idea is cancelled instead, they will get the points back (but no bonus).

It was a cool project to work on, we used a very simple micro-service CQRS architecture running on AngularJS, WebApi and MongoDB. Oh and everything was hosted on Azure.

After the contest, we decided to release all the sources, you can find them on my GitHub repository.

Enjoy!

DynamicConfig updates

Today I spent some time working on DynamicConfig , I had some minor/major refactorings in mind and also a couple of features I wanted to add.

Probably the most important update is the possibility now to save the configurations to file, operation performed directly by the library when a property changes. At the moment this feature is available only when a configuration was previously loaded from file, but I plan to extend this.

In a nutshell, all you have to do is load a configuration from file:

and then just update a property, the library will do the rest 🙂

Internally what is happening is that the configuration class ( ConfigObject ) now implements the IObservable<> interface,  so whenever a change occurs the registered observers will get a notification. The JsonConfigProvider instead implements IObserver<> and subscribes to the events during file loading.

A quick description to the Observer pattern can be found on CodeProject here ( although the pattern is very well know and I am sure doesn’t require introduction ). The idea is to maintain a list of objects that will be notified by the observer each time a specific event occurs on the observed class  itself.

On the ConfigObject class I also added a Parent property so that each message will be sent also to its subscribers.

Now I just have to add a couple of error checks and push the build to NuGet 🙂

© 2019 Davide Guida

Theme by Anders NorenUp ↑