I would like to know what is the best approach between using an operator and creating an open variable. My example is as follows: I have a manager class that inherits from one-time use, and this class has access to my dbcontext and methods. What I'm doing now is my cs class, which searches for this class and creates and destroys my object for my needs. For example:
public class StudentManager: IDisposable { private ISchoolUnitOfWork _unitOfWork; public StudentManager() { _unitOfWork = new SchoolUnitOfWork(); } public IEnumerable<Student> GetStudents() }
In my cs class, I:
private IEnumerable<Stundets> GetStudents() { using (StudentManager manager = new StudentManager()) { return = manager.GetStudents(); } }
OR
private StudentManager = new Studentmanager();
What is the best way to do this: have an instance of my StudentManager (just create a connection and destroy when to leave the page) or work with using ?
I am a little confused by this. Thanks in advance!
I update my context on the same manager that causes persistence in my context, which is the interface of my unit of work, I do not have direct access to the context, but when I create it, I build one type of my unit of work.
I keep my operations on the manager. So on my update, insert, change manager, I call the save method, for example:
public class StudentManager.... public Student UpdateStudent(Student student) { IStudentService service = new StudentService(_unitOfWork.StudentRepository); Student student= service.Update(student); _unitOfWork.Save(); return student; }
In general, I have the IUnitOfWork and UnitOfWork interface, also have an IRepository and a repository. And I just use the manager to not create an instance of my UnitOfWork directly, but with the manager to it ... I think it is legal and useful!
user2528557
source share