Call services inside service

Jun 27, 2015 at 10:22 PM
Edited Jun 27, 2015 at 10:27 PM

I've role service and I need to call user & log services in insert & update function inside role service. Or is there any best practices to achieve using this framework?

Jul 6, 2015 at 7:28 AM

If you using unity injection:
Option 1: you can inject the user and log service on the role service constructor then register all the repo and service on IOC. When you run the application they will automatic fill them in the constructor, you don't have to worry about them anymore.

Option 2: if you don't want to inject them on constructor you can call them directly by:

var clientService = UnityHelper.Container().Resolve<IClientService>();

with UnityHelper is the class they return the unity container on start_up folder when you install unity library.

Viet Anh,
Jul 6, 2015 at 1:13 PM
Edited Jul 6, 2015 at 1:16 PM
Thank you for your help.

Using this framework, I'm doing unitofwork transaction with multiple entities using InsertOrUpdateGraph as below,


var regionGraph = BindModel(viewModel);
regionGraph.ObjectState = ObjectState.Modified;

await unitOfWork.SaveChangesAsync();__ // I've to get masterId

regionGraph.fieldValues.ParentId = regionGraph.MasterId;

await unitOfWork.SaveChangesAsync();__


Should I call two times repository.InsertOrUpdateGraph(regionGraph); and await unitOfWork.SaveChangesAsync(); ?