Generic Interface Type with ILogger Interface is own class #187
-
|
Hello, I have seen many times in your book that in the constructor you use your own class. For example: Could you please explain what is used for? when and why should I use it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Using the |
Beta Was this translation helpful? Give feedback.
Using the
ILoggerinterface, you cannot inject the non-generic version of this interface. You'll get an error with this. TheILoggerinterface needs a name to use this for logging - this way you can find where log messages relate to. With this, you can either injectILoggerFactory, and pass a name using theCreateLoggermethod - or inject theILoggerinterface with a generic parameter using a class. TheILoggerimplementation than uses the name of the class as a category name for logging - e.g. in the code snippet the name "QuotesServer".