通过中间件注册服务提供商

时间:2016-10-12 07:58:39

标签: php laravel

在我的应用中,我已经注册了基于中间件的服务提供商。这是示例代码

public class MyWindow : Window
{
    public MyWindow()
    {
        DataContextChanged += OnDataContextChanged;
    }

    private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
    {
        InputBindings.Clear();
        var dataContext = DataContext as IZoomableViewModel;
        if (dataContext != null)
        {
            InputBindings.Add(new KeyBinding(dataContext.ZoomInCommand, Key.Add, ModifierKeys.Control));
            InputBindings.Add(new KeyBinding(dataContext.ZoomOutCommand, Key.Subtract, ModifierKeys.Control));
        }
    }
}

在另一个中间件上

class DomesticFlightMiddleware{

    public function handle($request, Closure $next)
    {
        app()->register('aunicaj\Providers\DomesticTravelServiceProvider');
    }

}

这工作正常,但是当我执行php artisan route:list时出现以下错误

构建(Controller)时,目标(接口)不可实例化。

是否有其他方式有条件地注册服务提供商?

0 个答案:

没有答案