Created
June 14, 2015 05:31
-
-
Save bitbonk/5060201f5639377ae00e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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