Skip to content

Instantly share code, notes, and snippets.

@confraria
Created April 11, 2018 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save confraria/5458fcec63394d5fdbed9458b3be5e64 to your computer and use it in GitHub Desktop.
Save confraria/5458fcec63394d5fdbed9458b3be5e64 to your computer and use it in GitHub Desktop.
sketch
import { Client, BasicAuth } from './core';
import * as services from './services';
export const serviceProviders: any = [
{ provide: BasicAuth, useValue: new BasicAuth()},
{ provide: Client, useFactory: factory.bind(Client), deps: [BasicAuth]}
].concat(Object.values(services).map(toProvider))
function factory(dep) {
return new this(dep);
}
function toProvider(service) {
return {
provide: service,
useFactory: factory.bind(service),
deps: [Client]
};
}
export { EventService } from '@c8y/client/lib/event';
export { InventoryService } from '@c8y/client/lib/inventory';
export { MeasurementService } from '@c8y/client/lib/measurement';
export { AlarmService } from '@c8y/client/lib/alarm';
export { OperationBulkService, OperationService } from '@c8y/client/lib/operation';
export { ApplicationService } from '@c8y/client/lib/application';
export { UserService } from '@c8y/client/lib/user';
export { TenantService } from '@c8y/client/lib/tenant';
export { SystemOptionsService } from '@c8y/client/lib/system-options';
export { TenantOptionsService } from '@c8y/client/lib/tenant-options';
export { TenantSecurityOptionsService } from '@c8y/client/lib/tenant-security-options';
export { AuditService } from '@c8y/client/lib/audit';
export { InventoryRoleService } from '@c8y/client/lib/inventory-role';
export { DeviceRegistrationService, DeviceRegistrationBulkService } from '@c8y/client/lib/device-registration';
export { UserRoleService } from "@c8y/client/lib/user-role";
export { UserGroupService } from "@c8y/client/lib/user-group";
export { Realtime } from '@c8y/client/lib/realtime';
import { NgModule, Injectable } from '@angular/core';
import { providers } from '@c8y/lib/providers'
import { AppStateService } from './app-state.service';
import { ManagedObjectResolver } from './resolvers';
@Injectable() {
class InventoryService {} // eventual future class extension
@NgModule({
imports: [],
exports: [],
declarations: [],
providers: [
AppStateService,
ManagedObjectResolver,
InventoryService,
].concat(providers)
})
export class C8yDataModule {}
import { InventoryService } from '@c8y/client/services';
@Component()
class MyComponent() {
constructor(inventory: InventoryService) {}
}
// after some time we need to create new classes just for angular for some reason by extending the orinal client class
// it's just a matter of replacing the import
import { InventoryService } from '@c8y/ng-data';
@Component()
class MyComponent() {
constructor(inventory: InventoryService) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment