Dispose in Unit Of Work

Asked

Viewed 105 times

-1

I have a web application and am using repository* and Unit Of Work.

In some examples I saw that after performing some change operation in the bank we should call the method Dispose().

I instancei the UnitOfWork:

    private UnitOfWork unitOfWork = new UnitOfWork();

When making an amendment to update and call the Dispose(), it is not possible to do the bind in the grid, Yeah, the object went through Dispose().

Alternatively, I’m using the using:

    using (UnitOfWork unitOfWork = new UnitOfWork())
    {
        //Código.
    }

My question is: using the Pattern Unit Of Work it is correct to use the using? If not, where should I call the Dispose()?

1 answer

0


Depends on the implementation of this class UnitOfWork. I know you have some that actually use the Dispose(). This seems to be the case, so it is to use whenever the object must be released.

From what is written in the question is not what you want, you want it to stay alive, so why is using the using? This feature is to ensure that the object dies at the end of the scope. Only use a resource when you want it.

So the problem has nothing to do with UnitOfWork Yes to what you wish to do.

Of course you will need to release the object at some point. You will need to see where the proper place to make this release is. We have no way of knowing, only you know your code and your need.

Memory management is not as simple as it seems.

By the comments the application is web, so it must execute in an ephemeral way, then at the end of the routine execution all memory will be released, so it is not necessary to use the using.

  • , my inquiry is exactly where to do Dispose(). Since in Web Application I’m not using controllers. The use of using() is only to release resource, however, for this I have to do several instances of Unit Of Work and the idea is not to have to instigate the class several times.

  • We have no way of knowing for sure, you just posted a snippet. But for the web there is a chance that you even need the using. If you run for a very short time, do one or more specific tasks and quit, which is very common on the web, it is not necessary. Ephemeral applications do not need so much care.

  • I understand. Radgrid of Telerik to do the CRUD, directly on the grid. So, basically, I have a Needdatasource, to load the data and use the Command for Insert, Update and Delete.

  • Who gave the negative could say what is wrong for me to correct. I am sure that there is nothing wrong, but the person can help everyone.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.