Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: Folder structure with service layer, interfaces, and mocks?

I recently started creating services layers and making declarations like:

MyService myService = new MyService();
myService.DoSomething();

This was inspired by some ASP.NET MVC videos and I like the pattern.

Then I started creating interfaces and mocks like:

IMyService myService = new MockMyService();
myService.DoSomething();

So I can isolate parts of the code to test. But now my service layer folder is loaded with classes, interfaces, and mock classes:

IServiceTypeA.cs
ServiceTypeA.cs
MockServiceTypeA.cs
IServiceTypeB.cs
ServiceTypeB.cs
MockServiceTypeB.cs
...
IServiceTypeZ.cs
ServiceTypeZ.cs
MockServiceTypeZ.cs

How do you organize these in a logical way?

like image 811
User Avatar asked Jul 08 '10 01:07

User


1 Answers

- Providers
    ServiceTypeA.cs
    ServiceTypeB.cs
    ServiceTypeC.cs
- Interfaces
    IServiceTypeA.cs
    IServiceTypeB.cs
    IServiceTypeC.cs
- Testing
    - Unit Tests
    - Mocks
        MockServiceTypeA.cs
        MockServiceTypeB.cs
        MockServiceTypeC.cs

Or you could use Mocking frameworks to have the Mock Services generated at runtime.

like image 76
Justin Niessner Avatar answered Sep 30 '22 01:09

Justin Niessner