Var students = _studentRepository.GetAllStudents() Public StudentService(IStudentRepository studentRepository) Private IStudentRepository _studentRepository My StudentService class, that uses a repository to get data from some store: public class StudentService Using (var db = _dbFactory.GetConnection()) Public StudentRepository(IDbFactory dbFactory) My Student Repository, injected with the DbFactory: public class StudentRepository : IStudentRepository Public DbFactory(string connectionString) Private readonly string _connectionString My DbFactory implementation: public class DbFactory : IDbFactory My DbFactory interface, to get the NPoco database connection object: public interface IDbFactory My interface for the Student Repository: public interface IStudentRepository Starting with the Student entity using NPoco filters/decorators: API library containing everything for the HTTP layer: Controllers, IoC containers, etc.BLL library containing all services that the API layer uses.DAL library containing everything for data access: Entities, repositories and a database factory.Common library containing DTO's and exceptions that are reused between BLL and API layer.Please tell me what you think so I can expand my knowledge and get better. One thing I'd like to add is a Unit Of Work using database transactions. Moq for mocking dependencies in unit tests. Autofac for IoC, to control injected dependencies.Service-Repository for interaction between BLL and DAL.Onion Architecture to seperate concerns.I'm trying to build a Web API using best practices, based on a simple proof-of-concept using students.
0 Comments
Leave a Reply. |