add dependency to @nx/typescript-domain
removed PortResolver consistent double quotes
This commit is contained in:
2059
package-lock.json
generated
Normal file
2059
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -25,5 +25,7 @@
|
||||
"ts-node": "^8.0.3",
|
||||
"typescript": "^3.3.3333"
|
||||
},
|
||||
"dependencies": {}
|
||||
"dependencies": {
|
||||
"@nx/typescript-domain": "git+https://solidt.eu/git/niels.kooiman/typescript-domain.git"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
|
||||
import { IPortResolver } from '../domain/exports/IPortResolver';
|
||||
|
||||
|
||||
export class PortResolver implements IPortResolver {
|
||||
private _container : any = {};
|
||||
constructor() {
|
||||
|
||||
}
|
||||
register<T>(name : string, fn : () => T) {
|
||||
this._container[name] = fn;
|
||||
}
|
||||
registerInstance<T>(name : string, fn : () => T) {
|
||||
let _instance : any = null;
|
||||
let getInstance = (fn : Function) => {
|
||||
return () => {
|
||||
if (!_instance) {
|
||||
_instance = fn();
|
||||
}
|
||||
return _instance;
|
||||
};
|
||||
};
|
||||
this._container[name] = getInstance(fn);
|
||||
}
|
||||
resolve<T>(name : string) : T {
|
||||
if (name in this._container && typeof this._container[name] == 'function') {
|
||||
return this._container[name]();
|
||||
}
|
||||
throw new Error('PortResolver can not resolve '+ name);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,10 @@
|
||||
|
||||
import { IPortResolver } from "./exports/IPortResolver";
|
||||
import { BaseResolver } from "@nx/typescript-domain"
|
||||
import { IMusicRepository } from "./imports/IMusicRepository";
|
||||
|
||||
class Dependencies
|
||||
class Dependencies extends BaseResolver
|
||||
{
|
||||
private portResolver: IPortResolver;
|
||||
private resolve<T>(name : string) : T {
|
||||
return this.portResolver.resolve(name);
|
||||
}
|
||||
public setResolver(portResolver : IPortResolver) {
|
||||
this.portResolver = portResolver;
|
||||
}
|
||||
|
||||
get MusicRepository() { return this.resolve<IMusicRepository>('IMusicRepository'); }
|
||||
get MusicRepository() { return this.resolve<IMusicRepository>("IMusicRepository"); }
|
||||
}
|
||||
const dependencies = new Dependencies();
|
||||
export default dependencies;
|
||||
export default dependencies;
|
||||
|
||||
@@ -1,18 +1,10 @@
|
||||
|
||||
import { IPortResolver } from "./exports/IPortResolver";
|
||||
import { BaseResolver } from "@nx/typescript-domain"
|
||||
import { IMusicCatalog } from "./exports/IMusicCatalog";
|
||||
|
||||
class Domain
|
||||
class Domain extends BaseResolver
|
||||
{
|
||||
private portResolver: IPortResolver;
|
||||
private resolve<T>(name : string) : T {
|
||||
return this.portResolver.resolve(name);
|
||||
}
|
||||
public setResolver(portResolver : IPortResolver) {
|
||||
this.portResolver = portResolver;
|
||||
}
|
||||
|
||||
public get musicCatalog() { return this.resolve<IMusicCatalog>('IMusicCatalog'); }
|
||||
public get musicCatalog() { return this.resolve<IMusicCatalog>("IMusicCatalog"); }
|
||||
}
|
||||
const domain = new Domain();
|
||||
export default domain;
|
||||
export default domain;
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
|
||||
|
||||
export interface IPortResolver {
|
||||
resolve<T>(name : string) : T;
|
||||
}
|
||||
@@ -1,25 +1,21 @@
|
||||
import { resolver } from '../../wiring/TestWiring';
|
||||
import "jasmine";
|
||||
import { resolver } from "../../wiring/TestWiring";
|
||||
|
||||
import { MusicCatalogService } from './MusicCatalogService';
|
||||
import { IMusicRepository } from '../imports/IMusicRepository';
|
||||
import { Track } from '../models/Track';
|
||||
import { IMusicCatalog } from '../exports/IMusicCatalog';
|
||||
import domain from '../domain';
|
||||
import { MusicCatalogService } from "./MusicCatalogService";
|
||||
import { IMusicRepository } from "../imports/IMusicRepository";
|
||||
import { IMusicCatalog } from "../exports/IMusicCatalog";
|
||||
import domain from "../domain";
|
||||
|
||||
let fakeMusicRepository = { get: () =>{ console.log('fakeMusicRepository'); } } as IMusicRepository;
|
||||
let fakeMusicRepository = { get: () =>{ console.log("fakeMusicRepository"); } } as IMusicRepository;
|
||||
|
||||
describe("MusicCatalog", () => {
|
||||
|
||||
it('should create a new MusicCatalog', (done) => {
|
||||
|
||||
let spiedGet = spyOn(fakeMusicRepository, 'get').and.returnValue([]);
|
||||
resolver.registerInstance<IMusicRepository>('IMusicRepository', () => fakeMusicRepository);
|
||||
resolver.registerInstance<IMusicCatalog>('IMusicCatalog', () => new MusicCatalogService());
|
||||
it("should create a new MusicCatalog", (done) => {
|
||||
let spiedGet = spyOn(fakeMusicRepository, "get").and.returnValue([]);
|
||||
resolver.registerInstance<IMusicRepository>("IMusicRepository", () => fakeMusicRepository);
|
||||
resolver.registerInstance<IMusicCatalog>("IMusicCatalog", () => new MusicCatalogService());
|
||||
domain.musicCatalog.get();
|
||||
|
||||
expect(spiedGet.calls.count()).toBe(1);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { BaseService } from './BaseService';
|
||||
import { BaseService } from "./BaseService";
|
||||
|
||||
import dependencies from "../../domain/dependencies";
|
||||
import { Track } from "../../domain/models/Track";
|
||||
|
||||
export class MusicCatalogService extends BaseService {
|
||||
export class MusicCatalogService extends BaseService {
|
||||
constructor(){
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import './wiring/Wiring';
|
||||
import { Track } from './domain/models/Track';
|
||||
import domain from './domain/domain';
|
||||
import "./wiring/Wiring";
|
||||
import { Track } from "./domain/models/Track";
|
||||
import domain from "./domain/domain";
|
||||
const musicCatalog = domain.musicCatalog;
|
||||
|
||||
export { musicCatalog, Track };
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { resolver } from '../wiring/TestWiring';
|
||||
import "jasmine";
|
||||
|
||||
import { resolver } from "../wiring/TestWiring";
|
||||
|
||||
import { MusicComponent } from "./MusicComponent";
|
||||
import { MusicCatalogService } from '../domain/services/MusicCatalogService';
|
||||
import { IMusicRepository } from '../domain/imports/IMusicRepository';
|
||||
import { IMusicCatalog } from '../domain/exports/IMusicCatalog';
|
||||
import domain from '../domain/domain';
|
||||
import { MusicCatalogService } from "../domain/services/MusicCatalogService";
|
||||
import { IMusicRepository } from "../domain/imports/IMusicRepository";
|
||||
import { IMusicCatalog } from "../domain/exports/IMusicCatalog";
|
||||
import domain from "../domain/domain";
|
||||
|
||||
|
||||
let fakeMusicRepository = {
|
||||
@@ -14,10 +16,10 @@ let fakeMusicRepository = {
|
||||
|
||||
describe("MusicComponent", () => {
|
||||
|
||||
it('should create a new MusicComponent', (done) => {
|
||||
//let spiedAdd = spyOn(fakeMusicRepository, 'add').and.returnValue([]);
|
||||
resolver.registerInstance<IMusicRepository>('IMusicRepository', () => fakeMusicRepository);
|
||||
resolver.registerInstance<IMusicCatalog>('IMusicCatalog', () => new MusicCatalogService());
|
||||
it("should create a new MusicComponent", (done) => {
|
||||
//let spiedAdd = spyOn(fakeMusicRepository, "add").and.returnValue([]);
|
||||
resolver.registerInstance<IMusicRepository>("IMusicRepository", () => fakeMusicRepository);
|
||||
resolver.registerInstance<IMusicCatalog>("IMusicCatalog", () => new MusicCatalogService());
|
||||
expect(domain.musicCatalog).not.toBe(null);
|
||||
|
||||
let musicComponent = new MusicComponent();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import domain from "../domain/domain"
|
||||
import dependencies from "../domain/dependencies"
|
||||
import { PortResolver } from "../adapters/PortResolver";
|
||||
import { PortResolver } from "@nx/typescript-domain"
|
||||
|
||||
export class TestWiring {
|
||||
portResolver: PortResolver;
|
||||
portResolver: PortResolver;
|
||||
constructor() {
|
||||
this.portResolver = new PortResolver();
|
||||
domain.setResolver(this.portResolver);
|
||||
@@ -16,4 +16,4 @@ export class TestWiring {
|
||||
|
||||
const wiring = new TestWiring();
|
||||
export const resolver = wiring.resolver;
|
||||
export default wiring;
|
||||
export default wiring;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import domain from "../domain/domain"
|
||||
import dependencies from "../domain/dependencies"
|
||||
import { PortResolver } from "../adapters/PortResolver";
|
||||
import { PortResolver } from "@nx/typescript-domain"
|
||||
import { VinylCatalog } from "../adapters/music/VinylCatalog";
|
||||
import { IMusicRepository } from "../domain/imports/IMusicRepository";
|
||||
import { IMusicCatalog } from "../domain/exports/IMusicCatalog";
|
||||
@@ -13,12 +13,12 @@ export class Wiring {
|
||||
dependencies.setResolver(portResolver);
|
||||
|
||||
// register imports
|
||||
portResolver.registerInstance<IMusicRepository>('IMusicRepository', () => new VinylCatalog());
|
||||
portResolver.registerInstance<IMusicRepository>("IMusicRepository", () => new VinylCatalog());
|
||||
|
||||
// register exports
|
||||
portResolver.registerInstance<IMusicCatalog>('IMusicCatalog', () => new MusicCatalogService());
|
||||
portResolver.registerInstance<IMusicCatalog>("IMusicCatalog", () => new MusicCatalogService());
|
||||
}
|
||||
}
|
||||
|
||||
const wiring = new Wiring();
|
||||
export default wiring;
|
||||
export default wiring;
|
||||
|
||||
Reference in New Issue
Block a user