问题描述
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);
这种情况表明它不存在!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)