Call services inside service

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

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?

Regards,
Jul 6, 2015 at 7:28 AM
Dear,

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,
Cheers
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,

unitOfWork.BeginTransaction();

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

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

regionGraph.fieldValues.ParentId = regionGraph.MasterId;

__repository.InsertOrUpdateGraph(regionGraph);
await unitOfWork.SaveChangesAsync();__

unitOfWork.Commit();

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

Regards,