Before answering your question, I would suggest reviewing your Logger architecture. Logging is always the same. You write a message somewhere. The only thing that is different is the part somewhere, so it makes sense to split your Logger into a common Logger and various Writers. This allows you to increase flexibility, for example, you can use the Composite template for recording to multiple registrars at once.
Regarding your question: in general, you want to avoid hard-coding dependencies in the code, because this will directly affect testability and reuse, for example. your Logger can only be used with this particular NullWriter. If you intend to distribute Logger, you will also have to distribute Writer.
However, assuming that you will still be distributing Logger with the entire Writers package, and you are also providing ctor injection tools, I don't see a big problem. You can still change the text of the Writer, if necessary, so everything is fine.
This is slightly different when we talk about interdependent dependencies. You will want to avoid this, for example. your classes in the Database package should not depend on the classes in the Logger package.
An alternative to assigning NullWriter from within Logger would be to use a LoggerFactory, which creates a Logger and the specified Writer, inserts Writer and returns a Logger.
source share