Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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 :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.