//Constructor injection public SpannerDataViewModel(IHttpContextAccessor httpContext, IFlightSpannersData flightSpannersData) { //IServiceProvider services = HttpContext.RequestServices; //[Optional] [FromServices] //var log = (IOrganizerData)services.GetService(typeof(IOrganizerData)); string code = httpContext.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; //Return the spanner based on the code var spanner = flightSpannersData.GetSpannerByCode(code); this.SpannerCode = spanner.SpannerCode; this.SpannerLicenseNo = spanner.SpannerLicenseNo; this.GroupName = spanner.GroupName; this.SpannerEmail = spanner.SpannerEmail; this.SpannerFName = spanner.SpannerFName; this.SpannerLName = spanner.SpannerLName; this.SpannerM1Name = spanner.SpannerM1Name; this.SpannerM2Name = spanner.SpannerM2Name; this.SpannerMobile1 = spanner.SpannerMobile1; this.SpannerMobile2 = spanner.SpannerMobile2; this.SpannerGender = spanner.SpannerGender; this.SpannerBirthday = spanner.SpannerBirthday; this.DepartmentName = spanner.DepartmentName; this.SpannerHireDate = spanner.SpannerHireDate; this.IsSpannerViewGroupData = spanner.IsSpannerViewGroupData; this.IsSpannerHasCar = spanner.IsSpannerHasCar; ////Get the Qualification of the spanner using GetQualificationSpanner(code) method this.SpannerQualification = flightSpannersData.GetQualificationOfSpanner(code); //Get the ApprovalList item of the model using GetApprovalSelectListItems(code) method this.ApprovalList = flightSpannersData.GetApprovalSelectListItems(code); }