Base solution for your next web application
Open Closed

UnitOfwork in PostInitialize #1979


User avatar
0
tiny created
public override void PostInitialize()
  {   
            var uowManager = IocManager.Resolve<IUnitOfWorkManager>();
            using (uowManager.Begin())
            {
                using (var taskAppServices = IocManager.ResolveAsDisposable<ReportTasks.ReportTaskAppService>())
                {
                    taskAppServices.Object.RestoreAllTask();
                }
            }
    }
public void RestoreAllTask()
  {
            var tasks = _reportTaskRepository.GetAllList().MapTo<List<ReportTaskEditDto>>();

            foreach (var task in tasks)
            {
                //todo
            }
   }

Hi, is there other best way to do? if i dont want IocManager.Resolve<IUnitOfWorkManager>() here.
[UnitOfWork] not work for PostInitialize.


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Instead of doing this, you can create a background job and start it in the PostInitialize of your module. See <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/Background-Jobs-And-Workers">http://aspnetboilerplate.com/Pages/Docu ... nd-Workers</a>.

    You can use UnitOfWork attribute in your backgroundJob. In this way, you dont block the initialization of your application.