'Global variable / state ASP.NET MVC 6

I have ITaskRepository that work with storage. TaskRepository(XML Storage) and TaskRepository(SQL Storage) different implementations of ITaskRepository. I want in View make selector with two options: XML / SQL. User select one of this option and whole application switches to selected storage.

I create dynamic dependency injection, but I don't know where I can save value - XML/SQL.

You have may any ideas? Thank you!

builder.Services.AddScoped<ITaskRepository>(provider =>
{
    string typeStorage = "sql"; // neccesary get from another place

    switch (typeStorage)
    {
        case "sql":
            {
                return provider.GetService<MicrosoftSQLServerDb.Repositories.TaskRepository>();
            }
        case "xml":
            {
                return provider.GetService<StorageXml.Repositories.TaskRepository>();
            }
        default:
            {
                return provider.GetService<MicrosoftSQLServerDb.Repositories.TaskRepository>();
            }
            
    }
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source