public object GetService(Type serviceType) { if (serviceType == typeof(UsersController)) { var context = new BlogSystemContext(); var repository = new DbUserRepository(context); return new UsersController(repository); } else if (serviceType == typeof(PostsController)) { var context = new BlogSystemContext(); var repository = new DbPostRepository(context); return new PostsController(repository); } else if (serviceType == typeof(TagsController)) { var context = new BlogSystemContext(); var repository = new DbTagRepository(context); return new TagsController(repository); } else { return null; } }
public object GetService(Type serviceType) { if (serviceType == typeof(UsersController)) { var dbContext = new ForumDbContext(); var repository = new DbUserRepository(dbContext); return(new UsersController(repository)); } else if (serviceType == typeof(ThreadsController)) { var dbContext = new ForumDbContext(); var threadRepository = new DbThreadRepository(dbContext); var userRepository = new DbUserRepository(dbContext); var categoryRepository = new DbCategoryRepository(dbContext); return(new ThreadsController( threadRepository, userRepository, categoryRepository)); } else if (serviceType == typeof(CategoriesController)) { var dbContext = new ForumDbContext(); var categoryRepository = new DbCategoryRepository(dbContext); var threadRepository = new DbThreadRepository(dbContext); var userRepository = new DbUserRepository(dbContext); return(new CategoriesController( categoryRepository, threadRepository, userRepository)); } else if (serviceType == typeof(PostsController)) { var dbContext = new ForumDbContext(); var postRepository = new DbPostRepository(dbContext); var userRepository = new DbUserRepository(dbContext); var threadRepository = new DbThreadRepository(dbContext); var voteRepository = new DbVoteRepository(dbContext); var commentRepository = new DbCommentRepository(dbContext); return(new PostsController( postRepository, userRepository, threadRepository, voteRepository, commentRepository)); } else { return(null); } }