Huge open source communities -
Comparison on # of published modules
var express = require('express');
var app = express();
var fs = require('fs');
// Code based configuration
app.configure(function(){
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.get('/', function(req, res) {
res.setHeader('Content-Type', 'text/html');
fs.createReadStream(__dirname + '/index.html').pipe(res);
});
var port = process.env.PORT || 3000;
app.listen(port);
console.log("Express server listening on port %d in %s mode", port, app.settings.env);
{
"name": "ShopWithMe",
"description": "ShopWithMe allows you to create and share your shopping lists with your friends to collaboratively edit them",
"version": "0.1.0",
"private": false,
"dependencies": {
"express": "3.x",
"mongoose": "3.5.x",
"winston": "0.6.x",
"moment": "2.1.x",
"request": "~2.27.0"
},
"devDependencies": {
"supertest": "0.5.x",
"mocha": "1.8.x",
"should": "1.2.x",
"grunt": "~0.4.0",
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-concat": "~0.1.1",
"grunt-contrib-uglify": "~0.1.0",
"grunt-contrib-watch": "~0.1.4",
"grunt-cafe-mocha": "~0.1.3",
"grunt-mocha-cov": "0.0.7"
},
"scripts": {
"test": "make test",
"blanket": {
"pattern": [
"handlers",
"models"
]
}
}
}
The open .Net ecosystem
Unlearn
Middleware
functions instead!
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.Use(
new Func<RequestDelegate, RequestDelegate>(
MyMiddleware));
// Other middleware components go here
}
RequestDelegate MyMiddleware(
RequestDelegate next)
{
RequestDelegate rd = (HttpContext ctxt) =>
{
ctxt.Response.WriteAsync(
"Hello, ASP.NET 5");
return next(ctxt);
};
return rd;
}
}
It doesn't contain the list of files inside the project!
{
"dependencies": {
"EntityFramework.SqlServer": "7.0.0-beta1",
"Microsoft.AspNet.Mvc": "6.0.0-beta1",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta1",
"Microsoft.AspNet.Security.Cookies": "1.0.0-beta1",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta1",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta1",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta1",
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta1",
"Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta1"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"aspnet50": { },
"aspnetcore50": { }
}
}
Everything is code based
public Startup()
{
Configuration = new Configuration()
.AddJsonFile("config.json")
//.AddIniFile("test.ini") Multiple sources
.AddEnvironmentVariables();
}
public void Configure(IApplicationBuilder app)
{
var day = Configuration.Get("demo:day");
var people = Configuration.Get<int>("demo:people");
var cool = Configuration.Get<bool>("demo:areTheyCool");
var tags = Configuration.Get("demo:tags").Split(';');
app.UseMvc(routes =>
{
// Classic routing code
});
}
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.UseServices(services =>
{
// Set up the dependencies
services.AddTransient<IFooService, FooService>();
services.AddSingleton<IFooRepository, FooRepository>();
});
}
}