C# DDD – Drawbacks of Implementing DDD Service as Static Class

cdomain-driven-designstatic-access

Can Services in a domain-driven design be implemented as C# static class? What are the drawbacks of this choice? Can it be implemented as a non-singleton non-static class?

Best Answer

As far as I can see, making a service class static does not affect its DDD'ness.

There are however other issues with static classes, primarily testability. It becomes difficult to unit test the class, and even more difficult to test classes that have dependencies to your static class.

Therefore I would always create the class as an instance class, and define an interface for it. This allows me to replace the class by test doubles when testing other classes that have a dependency to this class.

But it doesn't make it more DDD, it just makes it more TDD :)