Open Closed

Adding layer between Application service, and Repositories #489

bvz created

Currently, if I create a class that implements IApplicationService, or EfRepositoryBase, a UnitOfWork is created automatically. So if my ApplicationService gets a repository injected directly, the UnitOfWork created in the application service is used in the repository as well.

I want to create a layer between the repository and application service, called the manager layer.

But if I inject like this:

repository -> manager -> application service,

Repository is no longer injected into application service directly, and unit of work does not reach the repository through the manager.

So my question is, how can I get my manager to use the unit of work created in the application service, so that it is in turn used in the repository injected into the manager as well?

Putting [UnitOfWork] on the method inside the manager does the trick, as well as doing this: using (var uow = _unitOfWorkManager.Begin())

But I dont have to do this on every repository or application service method, so how can I achieve the same thing in the manager so that the same unit of work is shared across all three layers?

Thank you.

3 Answer(s)
  • 0
    hikalkan created

    Your UOW (automatically) created in application service method is used by manager and repositories, no problem. As a brief; a UOW is created at start of your app service method and completed at end of the method. You can call any class (manager, repository or whatever) and they all use the same UOW.

    Isn't it working like that for you?

  • 0
    bvz created

    When I posted the question, I could not make the error go away. (The error said something about the context being disposed, or something along those lines.)

    Now, when trying to set up the same scenario so that I can post code examples... it just works. I cannot get reproduce the error.

    Works perfectly, the UOW is used across all three layers. I don't know what I was doing wrong when I posted the original question.

    Thank you for your time and effort anyway! I really appreciate all the effort you put into this great framework.

  • 0
    hikalkan created

    You're welcome :)