Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public async Task UpdateStaffPlanStatus(long staffPlanId, string status)
- {
- // Update status in DB then commit
- await _context.SaveChangesAsync();
- // Doing logging in DB. Getting Error at below line.
- _logManager.LogStaffPlanStatusChange(staffPlanId, oldStatus, newStatus);
- }
- services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
- services.AddScoped<UserContext>();
- services.AddScoped<IStaffPlanService, StaffPlanService>();
- services.AddScoped<IStaffPlanDataService, StaffPlanDataService>();
- services.AddScoped<IStaffPlanLogManager, StaffPlanLogManager>();
- services.AddScoped<StaffPlanLogger, StaffPlanLogger>(provider =>
- {
- var pnyContextGlobal = provider.GetRequiredService<PnyContext>();
- StaffPlanLogger logger;
- using (var scope = provider.CreateScope())
- {
- // Get PnyContext object in another scope, different from object in StaffPlanDataService.
- var pnyContext = scope.ServiceProvider.GetRequiredService<PnyContext>();
- var userContext = scope.ServiceProvider.GetRequiredService<Core.Extensions.UserContext>();
- logger = new StaffPlanLogger(pnyContext, userContext);
- }
- // StaffPlanLogger will be created with diffrent PnyContext object
- return logger;
- });
- public class StaffPlanService : IStaffPlanService
- {
- readonly IStaffPlanDataService _dataService;
- /// <summary>
- /// Initializes a new instance of the <see cref="StaffPlanService"/> class.
- /// </summary>
- /// <param name="dataService">dataService</param>
- public StaffPlanService(IStaffPlanDataService dataService)
- {
- _dataService = dataService;
- }
- }
- public class StaffPlanDataService : IStaffPlanDataService
- {
- private IStaffPlanLogManager _logManager;
- private readonly PnyContext _context;
- private readonly UserContext _userContext;
- /// <summary>
- /// Initializes a new instance of the <see cref="StaffPlanDataService"/> class.
- /// </summary>
- /// <param name="context">PnyContext</param>
- public StaffPlanDataService(PnyContext context, UserContext userContext, IStaffPlanLogManager logManager)
- {
- _context = context;
- _userContext = userContext;
- _logManager = logManager;
- }
- }
- public class StaffPlanLogManager : IStaffPlanLogManager
- {
- private StaffPlanLogger _staffPlanLogger;
- readonly IAppLogger<StaffPlanLogManager> _logger;
- /// <summary>
- /// Initializes a new instance of the <see cref="StaffPlanLogManager"/> class.
- /// </summary>
- /// <param name="context"></param>
- /// <param name="staffPlanLogger">staffPlanLogger</param>
- /// <param name="logger">logger</param>
- public StaffPlanLogManager(StaffPlanLogger staffPlanLogger, IAppLogger<StaffPlanLogManager> logger)
- {
- _staffPlanLogger = staffPlanLogger;
- _logger = logger;
- }
- }
- public class StaffPlanLogger
- {
- private object lockObj = new object();
- private readonly PnyContext _context;
- private readonly UserContext _userContext;
- private readonly ObjectComparator<StaffPlan> comparator = new ObjectComparator<StaffPlan>();
- /// <summary>
- /// Initializes a new instance of the <see cref="StaffPlanLogger"/> class.
- /// </summary>
- /// <param name="context">PnyContext</param>
- public StaffPlanLogger(PnyContext context, UserContext userContext)
- {
- _context = context;
- _userContext = userContext;
- }
- }
- public async Task UpdateStaffPlanStatus(long staffPlanId, string status)
- {
- // Update status in DB then commit
- await _context.SaveChangesAsync();
- // Doing logging in DB. Getting Error at below line if await is removed.
- await _logManager.LogStaffPlanStatusChange(staffPlanId, oldStatus, newStatus);
- }
Add Comment
Please, Sign In to add comment