Dependency Injection in Static Class
I am writing Unit Tests for an existing codebase and am still getting speed.
There is a static class Logger, which is written this way (simplified):
public static class Logger
{
public static void Log(string message)
{
var myService = new Service();
myService.Save(message);
}
}
I would like to be able to Mock (using Moq) the Service class so that I can check the result. But there is obviously no way to do this with a class as it exists. But I don't see how a service dependency can be injected into a static class so that it can be mocked. Is there a way to do this? Or was it not written as a static class?
This is different from this question because the service is not a static class.
+3
source to share
No one has answered this question yet
See similar questions:
or similar: