500 ResolutionError:键'authentication.userProfileFactory'未绑定到上下文RestServer中的任何值

问题描述

    export const USER_PROFILE_FACTORY = BindingKey.create<
    UserProfileFactory<any>
    >('authentication.userProfileFactory');

这是未绑定上下文的用户配置文件工厂。我如何与上下文绑定。

import {registerauthenticationStrategy} from '@loopback/authentication/dist/types';
import {BootMixin} from '@loopback/boot';
import {ApplicationConfig,BindingScope,inject} from '@loopback/core';
import {RepositoryMixin} from '@loopback/repository';
import {Request,Response,RestApplication,RestServer} from '@loopback/rest';
import {RestExplorerComponent} from '@loopback/rest-explorer';
import {ServiceMixin} from '@loopback/service-proxy';
import morgan from 'morgan';
import path from 'path';
import {AuthenticationComponent} from './authentication.component';
import {TodoController} from './controllers';
import {UserController} from './controllers/user.controller';
import {UserRepository} from './repositories';
import {MyAuthenticationSequence} from './sequences/authentication.sequence';
import {BasicAuthenticationUserService} from './services/basic-auth-user-service';
import {BasicAuthenticationStrategy} from './strategies/basic-strategy';
import {UserProfileFactory} from './types';
export {ApplicationConfig};
export class TodoListApplication extends BootMixin(
  ServiceMixin(RepositoryMixin(RestApplication)),) {
  constructor(options: ApplicationConfig = {}) {
    super(options);
    // let userProfileFactory: UserProfileFactory<User>;
    // controller ...
    this.controller(UserController);
    this.controller(TodoController);
    // binding.../
    this.isBound('authentication.userProfileFactory');
    this.bind('services.authentication.basic.user.service.binding').toClass(
      BasicAuthenticationUserService,);
    //this.repository(UserRepository);
    server                                            //error here..
   .bind(AuthenticationBindings.USER_PROFILE_FACTORY) // error here..
   .to(myUserProfileFactory);                         // error here..
    this.bind('authentication.user.repo').toClass(UserRepository);
    //this.server.bind(AuthenticationBindings.USER_PROFILE_FACTORY);
    //this.bind('authentication.userProfileFactory').toProvider;
    // Set up the custom sequence and stratergy
    this.sequence(MyAuthenticationSequence);
    this.component(AuthenticationComponent);
    registerauthenticationStrategy(this,BasicAuthenticationStrategy);

    // Set up default home page
    this.static('/',path.join(__dirname,'../public'));

    this.component(RestExplorerComponent);

    this.projectRoot = __dirname;
    // Customize @loopback/boot Booter Conventions here
    this.bootOptions = {
      controllers: {
        // Customize ControllerBooter Conventions here
        dirs: ['controllers'],extensions: ['.controller.js'],nested: true,},};
    this.setupLogging();
  }

  private setupLogging() {
    // Register `morgan` express middleware
    // Create a middleware factory wrapper for `morgan(format,options)`
    const morganFactory = (config?: morgan.Options<Request,Response>) => {
      this.debug('Morgan configuration',config);
      return morgan('combined',config);
    };

    // Print out logs using `debug`
    const defaultConfig: morgan.Options<Request,Response> = {
      stream: {
        write: str => {
          this._debug(str);
        },};
    this.expressMiddleware(morganFactory,defaultConfig,{
      injectConfiguration: 'watch',key: 'middleware.morgan',});
  }
}

application.tx file i bind userservice and userrepository but how can i bound the user profile factory. if  try it's give error.

服务器 .bind(AuthenticationBindings.USER_PROFILE_FACTORY) .to(myUserProfileFactory);

这种情况表明它不存在!

我使用此REF:https://loopback.io/doc/en/lb4/apidocs.authentication.authenticationbindings.user_profile_factory.html

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...