Building a Yeoman webapi microservice template


Attempt1: Installation of existing ASP.NET template

  • Installs the .net dmx:
  • Install Yo
  • Update NPM: npm install -g npm
  • npm install -g yo bower grunt-cli gulp
  • Install the generator: npm install -g generator-aspnet

Run ASP.NET Template

  • yo aspnet
  • Select Web API Application
  • This creates the following:
? What type of application do you want to create? Web API Application
? What's the name of your ASP.NET application? TestApp
   create TestApp\.gitignore
   create TestApp\appsettings.json
   create TestApp\Dockerfile
   create TestApp\Startup.cs
   create TestApp\project.json
   create TestApp\Properties\launchSettings.json
   create TestApp\Controllers\ValuesController.cs
   create TestApp\wwwroot\
   create TestApp\wwwroot\web.config

Your project is now created, you can use the following commands to get going
    cd "TestApp"
    dnu restore
    dnu build (optional, build will also happen when it's run)
    dnx web
  • In VisualStudio 2015, we can open these projects by opening the project.json file

Attempt2: generator-webapi

  • generator-webapi
  • npm install -g generator-webapi
  • yo webapi
  • Generates a WebAPI 2 Project
  • Good example to work off

Attempt3: webapi owin

Establishing our MVP

1st we need to establish what our MVP is.

What is our MVP?

Core Requirements

  • WebAPI 2
  • .NET 4.6
  • Input Field: NameSpace
  • Input Field: ProjectName

Hosting Requirements

  • How do we get the package? It would be nice to be able to install the yo template from our private myget account
  • Need to be able to generate a new service from the template
  • how to add your generator to the yo list

Add Features: Logging

  • CorrelatorSharp
  • LogEntires
  • NLog

Add Features: IOC

  • Ninject
  • Correlated Inbound and outbound request logging

Building the generator

Ok, we have now established what our MVP is... so lets do it!

Reading up on building our genertor

Creating the generator

  • We're going to be lazy and use the generator:
  • Install the generator npm install -g generator-generator
  • Run the generator: yo generator
  • Below are the steps/answers to the questions that we went through:
$ yo generator
? Your generator name generator-micro-webapi
Your generator must be inside a folder named generator-micro-webapi
I'll automatically create this folder.
? Description Micro Service boilerplate using WebApi2
? Project homepage url
? Author's Name Phil Hack
? Author's Email
? Author's Homepage
? Package keywords (comma to split) webapi,webapi2,microservice,micro service
? Send coverage reports to coveralls (Y/n) Y
? GitHub username or organization () marketinvoice
? Which license do you want to use?
  Apache 2.0
  Internet Systems Consortium (ISC)
  No License (Copyrighted)

Test the generator

  • Add the dependency: npm install eslint-config-xo --save-dev
  • Run the tests: npm test

Test the generator locally


Issues? Call the Yeoman Doctor

  • Check that yeoman is correctly configured, by running: yo doctor

Further improvements

cd /c/dev/InnovationDay/MicroServiceTemplate
mkdir test
cd test
yo microwebapi

## Example Tests
* npm test

## To Publish our npm package
> * ensure that the keyword ```yeoman-generator``` exists so that yeoman automatically picks this up
> * Signup for an account on
> ```npm add user```
> ```npm publish --access public```

## Questions:
* Is this useful?
* What additional configurations do we want added?
* Should we open source this?

check with andy for his template
c# client
EF / Dapper?   -option