-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #330 from christophercr/feature/injection-tokens
chore(core): define InjectionTokens for every service and a forRoot() method for every module
- Loading branch information
Showing
31 changed files
with
261 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./configuration/entities" | ||
export * from "./configuration/entities"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
import { NgModule } from "@angular/core"; | ||
import { HttpClient, HttpClientModule } from "@angular/common/http"; | ||
import { StarkHttpServiceImpl, starkHttpServiceName } from "./services"; | ||
import { StarkLoggingService, starkLoggingServiceName } from "../logging"; | ||
|
||
// FIXME: remove this factory once LoggingService and SessionService are implemented | ||
export function starkHttpServiceFactory(httpClient: HttpClient, starkLoggingService: StarkLoggingService): StarkHttpServiceImpl<any> { | ||
const sessionService: any = { | ||
fakePreAuthenticationHeaders: new Map<string, string>([["nbb-dummy-header", "some value"], ["nbb-another-header", "whatever"]]) | ||
}; | ||
|
||
return new StarkHttpServiceImpl(starkLoggingService, sessionService, httpClient); | ||
} | ||
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from "@angular/core"; | ||
import { HttpClientModule } from "@angular/common/http"; | ||
import { STARK_HTTP_SERVICE, StarkHttpServiceImpl } from "./services"; | ||
|
||
@NgModule({ | ||
imports: [HttpClientModule], | ||
providers: [ | ||
// FIXME: replace this Factory provider by a simple Class provider once LoggingService and SessionService are implemented | ||
{ provide: starkHttpServiceName, useFactory: starkHttpServiceFactory, deps: [HttpClient, starkLoggingServiceName] } | ||
] | ||
imports: [HttpClientModule] | ||
}) | ||
export class StarkHttpModule {} | ||
export class StarkHttpModule { | ||
// instantiate the services only once since they should be singletons | ||
// so the forRoot() should be called only by the AppModule | ||
// see https://angular.io/guide/singleton-services#forroot | ||
public static forRoot(): ModuleWithProviders { | ||
return { | ||
ngModule: StarkHttpModule, | ||
providers: [{ provide: STARK_HTTP_SERVICE, useClass: StarkHttpServiceImpl }] | ||
}; | ||
} | ||
|
||
// prevent this module from being re-imported | ||
// see https://angular.io/guide/singleton-services#prevent-reimport-of-the-coremodule | ||
public constructor( | ||
@Optional() | ||
@SkipSelf() | ||
parentModule: StarkHttpModule | ||
) { | ||
if (parentModule) { | ||
throw new Error("StarkHttpModule is already loaded. Import it in the AppModule only"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./testing/http.mock" | ||
export * from "./testing/http.mock"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,37 @@ | ||
import { NgModule } from "@angular/core"; | ||
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from "@angular/core"; | ||
import { ActionReducerMap, StoreModule } from "@ngrx/store"; | ||
|
||
import { loggingReducer, StarkLoggingState } from "./reducers"; | ||
import { StarkLoggingActions } from "./actions"; | ||
import { StarkLoggingServiceImpl, starkLoggingServiceName } from "./services"; | ||
import { StarkLoggingServiceImpl, STARK_LOGGING_SERVICE } from "./services"; | ||
|
||
const reducers: ActionReducerMap<StarkLoggingState, StarkLoggingActions> = { | ||
logging: loggingReducer | ||
}; | ||
|
||
@NgModule({ | ||
imports: [StoreModule.forFeature("StarkLogging", reducers)], | ||
declarations: [], | ||
providers: [{ provide: starkLoggingServiceName, useClass: StarkLoggingServiceImpl }] | ||
imports: [StoreModule.forFeature("StarkLogging", reducers)] | ||
}) | ||
export class StarkLoggingModule {} | ||
export class StarkLoggingModule { | ||
// instantiate the services only once since they should be singletons | ||
// so the forRoot() should be called only by the AppModule | ||
// see https://angular.io/guide/singleton-services#forroot | ||
public static forRoot(): ModuleWithProviders { | ||
return { | ||
ngModule: StarkLoggingModule, | ||
providers: [{ provide: STARK_LOGGING_SERVICE, useClass: StarkLoggingServiceImpl }] | ||
}; | ||
} | ||
|
||
// prevent this module from being re-imported | ||
// see https://angular.io/guide/singleton-services#prevent-reimport-of-the-coremodule | ||
public constructor( | ||
@Optional() | ||
@SkipSelf() | ||
parentModule: StarkLoggingModule | ||
) { | ||
if (parentModule) { | ||
throw new Error("StarkLoggingModule is already loaded. Import it in the AppModule only"); | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/stark-core/src/logging/services/logging.service.intf.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
import { NgModule } from "@angular/core"; | ||
import { StarkRoutingServiceImpl, starkRoutingServiceName } from "./services"; | ||
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from "@angular/core"; | ||
import { UIRouterModule } from "@uirouter/angular"; | ||
import { StarkRoutingServiceImpl, STARK_ROUTING_SERVICE } from "./services"; | ||
|
||
@NgModule({ | ||
imports: [], | ||
declarations: [], | ||
providers: [{ provide: starkRoutingServiceName, useClass: StarkRoutingServiceImpl }] | ||
imports: [UIRouterModule.forChild()] | ||
}) | ||
export class StarkRoutingModule {} | ||
export class StarkRoutingModule { | ||
// instantiate the services only once since they should be singletons | ||
// so the forRoot() should be called only by the AppModule | ||
// see https://angular.io/guide/singleton-services#forroot | ||
public static forRoot(): ModuleWithProviders { | ||
return { | ||
ngModule: StarkRoutingModule, | ||
providers: [{ provide: STARK_ROUTING_SERVICE, useClass: StarkRoutingServiceImpl }] | ||
}; | ||
} | ||
|
||
// prevent this module from being re-imported | ||
// see https://angular.io/guide/singleton-services#prevent-reimport-of-the-coremodule | ||
public constructor( | ||
@Optional() | ||
@SkipSelf() | ||
parentModule: StarkRoutingModule | ||
) { | ||
if (parentModule) { | ||
throw new Error("StarkRoutingModule is already loaded. Import it in the AppModule only"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/stark-core/src/session/services/session.service.intf.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,36 @@ | ||
import { NgModule } from "@angular/core"; | ||
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from "@angular/core"; | ||
import { ActionReducerMap, StoreModule } from "@ngrx/store"; | ||
|
||
import { sessionReducer, StarkSessionState } from "./reducers"; | ||
import { StarkSessionActions } from "./actions"; | ||
import { StarkSessionServiceImpl, starkSessionServiceName } from "./services"; | ||
import { StarkSessionServiceImpl, STARK_SESSION_SERVICE } from "./services"; | ||
|
||
const reducers: ActionReducerMap<StarkSessionState, StarkSessionActions> = { | ||
session: sessionReducer | ||
}; | ||
|
||
@NgModule({ | ||
imports: [StoreModule.forFeature("StarkSession", reducers)], | ||
declarations: [], | ||
providers: [{ provide: starkSessionServiceName, useClass: StarkSessionServiceImpl }] | ||
imports: [StoreModule.forFeature("StarkSession", reducers)] | ||
}) | ||
export class StarkSessionModule {} | ||
export class StarkSessionModule { | ||
// instantiate the services only once since they should be singletons | ||
// so the forRoot() should be called only by the AppModule | ||
// see https://angular.io/guide/singleton-services#forroot | ||
public static forRoot(): ModuleWithProviders { | ||
return { | ||
ngModule: StarkSessionModule, | ||
providers: [{ provide: STARK_SESSION_SERVICE, useClass: StarkSessionServiceImpl }] | ||
}; | ||
} | ||
|
||
// prevent this module from being re-imported | ||
// see https://angular.io/guide/singleton-services#prevent-reimport-of-the-coremodule | ||
public constructor( | ||
@Optional() | ||
@SkipSelf() | ||
parentModule: StarkSessionModule | ||
) { | ||
if (parentModule) { | ||
throw new Error("StarkSessionModule is already loaded. Import it in the AppModule only"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.