Dispose in Unit Of Work

0

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

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

Instantiated UnitOfWork :

    private UnitOfWork unitOfWork = new UnitOfWork();

When you make a update change and call Dispose() , you can not bind in grid passed Dispose() .

Alternatively, I'm using using :

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

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

    
asked by anonymous 04.12.2017 / 13:23

1 answer

0

Depends on the implementation of this class UnitOfWork . I know there are some who actually use Dispose() . This seems to be the case, so it's to use whenever the object should be released.

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

So the problem is not about UnitOfWork but about what you want to do.

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

Memory management is not as simple as it sounds.

By the comments the application is web, so it should run ephemeral, so at the end of the execution of the routine all the memory will be released, so it is not necessary to use using .

    
04.12.2017 / 13:29