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 class Category | |
{ | |
public string Id { get; set; } = Guid.NewGuid().ToString(); | |
public string Name { get; set; } | |
} |
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
using Models; | |
public static class CategoryProvider | |
{ | |
public static List<Category> Categories = Enumerable.Range(1, 5).Select(i => new Category { Name = $"Category {i}" }).ToList(); | |
} |
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
using Models; | |
using Providers; | |
public class CategoryController : ApiController | |
{ | |
[ResponseType(typeof(List<Category>))] | |
public IHttpActionResult Get() => Ok(CategoryProvider.Categories); | |
[ResponseType(typeof(Category))] | |
public IHttpActionResult Get(string id) => Ok(CategoryProvider.Categories.FirstOrDefault(x => x.Id == id)); |
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 class Container | |
{ | |
Dictionary<Type, Func<Container, object>> factory; | |
public Container() | |
{ | |
factory = new Dictionary<Type, Func<Container, object>>(); | |
} | |
public void Register<TReferenceType, TObjectType>(Func<Container, TObjectType> creator = null) | |
where TObjectType : TReferenceType |