Skip to content

Instantly share code, notes, and snippets.

View fatihdgn's full-sized avatar

Fatih Doğan fatihdgn

View GitHub Profile
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
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));
using Models;
public static class CategoryProvider
{
public static List<Category> Categories = Enumerable.Range(1, 5).Select(i => new Category { Name = $"Category {i}" }).ToList();
}
public class Category
{
public string Id { get; set; } = Guid.NewGuid().ToString();
public string Name { get; set; }
}