Dispose in CustomerController

Jan 15, 2015 at 12:13 AM
Hi, I see below code in CustomerController:
protected override void Dispose(bool disposing)
{
    if (disposing)
    {
        _unitOfWorkAsync.Dispose();
    }
    base.Dispose(disposing);
}
Also I see the code in UnityConfig
            .RegisterType<IDataContextAsync, NorthwindContext>(new PerRequestLifetimeManager())
            .RegisterType<IUnitOfWorkAsync, UnitOfWork>(new PerRequestLifetimeManager())
As the life cycle for IDataContextAsync and IUnitOfWorkAsync is per request, why we still need to dispose in controller? for thread safe?
Jan 18, 2015 at 9:16 PM
Edited Jan 18, 2015 at 9:16 PM
NorthwindContext and UnitOfWork would get disposed by Unity,and you don't have to call Dispose() on it yourself.
More Details: Unity DI Inject DbContext with PerRequestLifetimeManager
Coordinator
Feb 12, 2015 at 6:45 PM
@Berlin, adding to @daniloko's response, it's best practice for us to illustrate proper dispose regardless if there is a DI/IoC framework to handle this or not, reason being is because not everyone will be using this framework with a DI/IoC framework (e.g. NorthwindTest integration test for this solution does not).
Marked as answer by lelong37 on 2/12/2015 at 11:45 AM