Using Global Variables in export controller

Hi,
I would like to use some global variables in one of the export controller methods so I have declared it as below

        private readonly BWiseContext context;
        private readonly BWiseService service;
        private readonly GlobalsService Globals;
        public ExportBWiseController(BWiseContext context, BWiseService service, GlobalsService globals)
        {
            this.service = service;
            this.context = context;
            Globals = globals;
        }

and on button click below code

await BWise.ExportBankMainsToCSV();

How ever I get following error during runtime at the export button click event.


If I remove the globals variable from the controller the error is resolved. Could you please guide how to use global variable in export controller
Thanks

Unfortunately you can't use the globals service in a controller. Services added via AddScoped are not the same instance as the one available to the blazor components. As a result the global properties will be missing (not set) in the controller. This is an implementation detail of how Blazor is implemented - the Blazor code (components) runs in a separate thread/process than the controllers.

A possible workaround is to pass the required properties as additional parameters of the controller methods.

Updated my reply to be technically sound.

Thanks for your valuable feedback.