Created
August 21, 2013 06:16
-
-
Save JakeGinnivan/6290877 to your computer and use it in GitHub Desktop.
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
| public class FooController : Controller{ | |
| IService service; | |
| public FooController(IService service){ | |
| this.service = service; | |
| } | |
| public ActionResult Bar(){ | |
| service.DoStuff(); | |
| } | |
| } | |
| public interface IService { | |
| void DoStuff(); | |
| } | |
| public class MockService : IService{ | |
| ... | |
| } | |
| public class RealService : IService { | |
| ... | |
| } | |
| public class ServiceSwitcher : IService { | |
| RealService realService; | |
| MockService mockService; | |
| public ServiceSwitcher(RealService realService, MockService mockService){ | |
| this.realService = realService; | |
| this.mockService = mockService; | |
| } | |
| public void DoStuff(){ | |
| if (Condition()) | |
| mockService.DoStuff(); | |
| else | |
| realService.DoStuff(); | |
| } | |
| } | |
| void COntainerRegistration(){ | |
| var cb = new ContainerBuilder(); | |
| cb.RegisterType<RealService>().AsSelf(); | |
| cb.RegisterType<MockService>().AsSelf(); | |
| cb.RegisterType<ServiceSwitcher>().As<IService>(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment