Skip to content

ISP complicated or violated with wessberg/DI #4

Description

@DScheglov

Hey, guys,

the library uses interface names as tokens and it complicates following to Interface Segregation Princinple.

In example:

interface IInfoLogger {
  info(message: string): void;
}

interface IWarnLogger {
  warn(message: string): void;
}

interface IErrorLogger {
  error(error: Error): void;
}

All of these interfaces belongs to the clients of some logger, for example:

class MyService {
  consturctor(private readonly logger: IInfoLogger) {
    logger.info(...);
  }
}
class MyOtherService {
  consturctor(private readonly logger: IWarnLogger) {
    logger.warn(...);
  }
}
class MyThirdService {
  consturctor(private readonly logger: IErrorLogger) {
    logger.error(new Error('....'));
  }
}

and finally I have the implementation

export interface ILogger extends IInfoLogger, IWarnLogger, IErrorLogger {}

export default class ConsoleLogger implements ILogger {
 ....
}

So, with wessberg/DI I have to register the ConsoleLogger three times with different client owned interfaces, and it could be ok, but when we need to make ConsoleLogger a singleton shared between all clients, -- we can't do it with wessberg/DI, can we?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions