Skip to content

Instantly share code, notes, and snippets.

@bitbonk
Created June 14, 2015 05:31
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 bitbonk/5060201f5639377ae00e to your computer and use it in GitHub Desktop.
Save bitbonk/5060201f5639377ae00e to your computer and use it in GitHub Desktop.
public void Configure(IAppBuilder appBuilder)
{
this.container.RegisterSingle<ITodoRepository>(() => new TodoDatabase(this.slowness, this.todoCount));
var httpConfig = new HttpConfiguration();
httpConfig.Routes.MapHttpRoute(
"DefaultApi",
"{controller}/{id}",
new { id = RouteParameter.Optional });
httpConfig.DependencyResolver = new SimpleInjectorDependencyResolver(this.container);
appBuilder.UseWebApi(httpConfig);
}
public class TodoController : ApiController
{
private readonly ITodoRepository repository;
public TodoController(ITodoRepository repository)
{
Ensure.ArgumentNotNull(repository, "repository");
this.repository = repository;
}
public async Task DeleteAsync(int id)
{
await this.repository.RemoveAsync(id);
}
public async Task<Todo> GetAsync(int id)
{
return await this.repository.GetByIdAsync(id);
}
public async Task<IEnumerable<Todo>> GetAsync()
{
return await this.repository.GetAllAsync();
}
public async Task PutAsync(Todo todo)
{
await this.repository.AddAsync(todo);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment