Created
August 8, 2012 07:29
-
-
Save mikeminutillo/3293123 to your computer and use it in GitHub Desktop.
Use Fake implementations at debug time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var builder = new ContainerBuilder(); | |
builder.AddModule(new ModuleA()); | |
builder.AddModule(new ModuleB()); | |
builder.AddModule(new DebugFakesModule()); | |
var container = builder.Build(); | |
// Will be FakeEmailService if compiled with DEBUG | |
var emailService = builder.Resolve<IEmailService>(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DebugFakesModule : Module | |
{ | |
protected override void Load(ContainerBuilder builder) | |
{ | |
#if DEBUG | |
builder.RegisterAssemblyTypes(ThisAssembly) | |
.Where(x => x.Name.StartsWith("Fake")) | |
.AsImplementedInterfaces() | |
.SingleInstance(); | |
#endif | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Only gets used when compiled as a DEBUG compiler switch | |
class FakeMailService : IEmailService | |
{ | |
// Fake impl | |
} | |
class EmailService : IEmailService | |
{ | |
// normal impl | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment