Skip to content

Instantly share code, notes, and snippets.

@beyond-code-github
Created September 20, 2013 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beyond-code-github/6642320 to your computer and use it in GitHub Desktop.
Save beyond-code-github/6642320 to your computer and use it in GitHub Desktop.
Example of dependency injection using Require
this.Get["Products" / (ʃLong)"Id"] = _ =>
{
var service = _.Require<IProductsService>();
return service.Get(_.Parameters.Id);
};
this.Post["Products"] = _ =>
{
var service = _.Require<IProductsService>();
var product = _.Bind<Product>();
service.Create(product);
return _.Request.CreateResponse(
HttpStatusCode.Created,
new { Link = new { href = string.Format("http://api.localhost/products/{0}", product.Id) } });
};
@damianh
Copy link

damianh commented Sep 23, 2013

This is Service Location, no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment