اشتراکها
اشتراکها
فیلتر و سورت سریع داده های حجیم
اشتراکها
جستجوی افزایشی در Visual Studio
اشتراکها
ایجاد یک Reverse Proxy در NET Core.
This article will show you how to implement a reverse proxy in C# and .NET Core to overcome specific needs that you could hardly solve with an out-of-the-box software. You can find the code of the final project on this GitHub repository.
C# 7 is a major update with a lot of interesting new capabilities. And while there are plenty of articles on what you can do with it, there aren't quite as many on what you should do with it. Using the principles found in the .NET Framework Design Guidelines, we're going to take a first pass at laying down strategies for getting the most from these new features.
با تغییر کلاس سرویس AppConfigService به شکل زیر :
و تغییر ماژول CoreModule به شکل زیر :
با خطای زیر مواجه شدم لطفا راهنمایی بفرمائید :
import { HttpClient } from "@angular/common/http"; import { Injectable } from "@angular/core"; @Injectable() export class AppConfigService { private config: IAppConfig; constructor(private http: HttpClient) { } loadClientConfig(): Promise<any> { return this.http.get<IAppConfig>("assets/client-config.json") .toPromise() .then(config => { this.config = config; console.log("Config", this.config); }) .catch(err => { return Promise.reject(err); }); } get configuration(): IAppConfig { if (!this.config) { throw new Error("Attempted to access configuration property before configuration data was loaded."); } return this.config; } } export interface IAppConfig { apiEndpoint: string; loginPath: string; logoutPath: string; refreshTokenPath: string; accessTokenObjectKey: string; refreshTokenObjectKey: string; adminRoleName: string; }
و تغییر ماژول CoreModule به شکل زیر :
import { NgModule, Optional, SkipSelf, APP_INITIALIZER } from "@angular/core"; import { CommonModule } from "@angular/common"; import { RouterModule } from "@angular/router"; import { HTTP_INTERCEPTORS } from "@angular/common/http"; // import RxJs needed operators only once import "./services/rxjs-operators"; import { HeaderComponent } from "./component/header/header.component"; import { AuthGuard } from "./services/auth.guard"; import { AuthInterceptor } from "./services/auth.interceptor"; import { AuthService } from "./services/auth.service"; import { AppConfigService } from "./services/app-config.service"; import { BrowserStorageService } from "./services/browser-storage.service"; @NgModule({ imports: [CommonModule, RouterModule], exports: [ // components that are used in app.component.ts will be listed here. HeaderComponent ], declarations: [ // components that are used in app.component.ts will be listed here. HeaderComponent ], providers: [ // global singleton services of the whole app will be listed here. BrowserStorageService, AppConfigService, AuthService, AuthGuard, { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }, { provide: APP_INITIALIZER, useFactory: (config: AppConfigService) => () => config.loadClientConfig(), deps: [AppConfigService ], multi: true } ] }) export class CoreModule { constructor( @Optional() @SkipSelf() core: CoreModule) { if (core) { throw new Error("CoreModule should be imported ONLY in AppModule."); } } }
Error: Provider parse errors:
Cannot instantiate cyclic dependency! ApplicationRef ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1
Cannot instantiate cyclic dependency! ApplicationRef ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1