In Laravel 6, based on ForgetInstance, remove the resolved instance from the instance cache
1. To set the configuration value at runtime, pass an array to the config function, which is reset in the middleware
config(['theme.view_storage' => 'file']);
2. The Singleton method binds a class or interface to a container that is only parsed once. Once the singleton binding is resolved, the same object instance will be returned to the container in subsequent calls. Because the previous configuration items are used when binding. Therefore, an error is reported at runtime. To print the instance, expect ViewStorage to be FileViewStorage, but in fact it is DbViewStorage. as shown in Figure 1
3. Decide to remove the resolved instance from the instance cache based on the ForgetInstance . Register again.
config(['theme.view_storage' => 'file']);
$this->forgetRegisterViewStorageInstance();
/**
* 从实例缓存中移除已解析的 ViewStorage 相关实例,再次注册。
* @return void
* @throws BindingResolutionException
*/
private function forgetRegisterViewStorageInstance() {
app()->forgetInstance(ViewFactoryRegistry::class);
// ...
//注册当前ViewStorage的全部服务
$viewFactoryRegistry = app()->make(ViewFactoryRegistry::class);
$viewFactoryRegistry
->getFactory(config('theme.view_storage'))
->register();
}
4. To print the instance again, it is expected that ViewStorage is FileViewStorage, but it is actually FileViewStorage. in line with expectations. as shown in Figure 2

